From b5b8344888f37f96dab2e5fd98648d06789c1369 Mon Sep 17 00:00:00 2001 From: hamid zarghami Date: Wed, 22 Jul 2026 16:11:27 +0330 Subject: [PATCH] fix pagination bug --- src/components/Input.tsx | 18 ++++++++++-------- src/pages/customer/List.tsx | 4 +++- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/components/Input.tsx b/src/components/Input.tsx index c97efc5..c241f6f 100644 --- a/src/components/Input.tsx +++ b/src/components/Input.tsx @@ -1,5 +1,5 @@ import { SearchNormal } from "iconsax-react"; -import { FC, InputHTMLAttributes, useEffect, useState } from "react"; +import { FC, InputHTMLAttributes, useEffect, useRef, useState } from "react"; import EyeIcon from "../assets/images/eye.svg"; import { clx } from "../helpers/utils"; import Error from "./Error"; @@ -30,6 +30,8 @@ const Input: FC = (props: Props) => { const [showPassword, setShowPassword] = useState(false); const [search, setSearch] = useState(""); + const onChangeSearchFinalRef = useRef(props.onChangeSearchFinal); + onChangeSearchFinalRef.current = props.onChangeSearchFinal; const inputClass = clx( "w-full h-10 text-black block px-4 text-xs rounded-xl border border-border", @@ -68,13 +70,13 @@ const Input: FC = (props: Props) => { }, [props.value]); useEffect(() => { - if (props.variant === "search" && props.onChangeSearchFinal) { - const timeout = setTimeout(() => { - props.onChangeSearchFinal?.(search); - }, 1000); - return () => clearTimeout(timeout); - } - }, [search, props]); + if (props.variant !== "search" || !onChangeSearchFinalRef.current) return; + + const timeout = setTimeout(() => { + onChangeSearchFinalRef.current?.(search); + }, 1000); + return () => clearTimeout(timeout); + }, [search, props.variant]); return (
diff --git a/src/pages/customer/List.tsx b/src/pages/customer/List.tsx index 1d5f6ea..fb18b22 100644 --- a/src/pages/customer/List.tsx +++ b/src/pages/customer/List.tsx @@ -19,7 +19,9 @@ const CustomerList: FC = () => { const getCustomers = useGetCustomers(page, limit, false, search); const handleSearch = (value: string) => { - setPage(1); + if (value !== search) { + setPage(1); + } setSearch(value); };