Replies: 1 comment
-
You can try this (NOT TESTED): "use client";
import qs from "query-string";
import { Search } from "lucide-react";
import { useDebounceValue } from "usehooks-ts";
import { useRouter } from "next/navigation";
import { ChangeEvent, useEffect } from "react";
import { Input } from "@/components/ui/input";
export const SearchInput = () => {
const router = useRouter();
const [debouncedValue, setDebouncedValue] = useDebounceValue("", 500);
const handleChange = (e: ChangeEvent<HTMLInputElement>) => {
setDebouncedValue(e.target.value);
};
useEffect(() => {
const url = qs.stringifyUrl(
{
url: "/",
query: {
search: debouncedValue,
},
},
{ skipEmptyString: true, skipNull: true }
);
router.push(url);
}, [debouncedValue, router]);
return (
<div className="w-full relative">
<Search className="absolute top-1/2 left-3 transform -translate-y-1/2 text-muted-foreground h-4 w-4" />
<Input
className="w-full max-w-[516px] pl-9"
placeholder="Search boards"
onChange={handleChange}
/>
</div>
);
}; I've swapped |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am a newbie who just learned. When I followed the instructions, I found that useDebounce has been deprecated. It has been replaced by useDebounceValue and useDebounceCallback. However, my ability is limited, and English is not my mother tongue. I want to know how to implement it in the code. Same logic.
Thank a lot.
Beta Was this translation helpful? Give feedback.
All reactions