-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSearchInput.tsx
40 lines (30 loc) · 877 Bytes
/
SearchInput.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"use client";
import useDebounce from "@/hooks/useDebounce";
import Input from "./ui/Input";
import { useRouter } from "next/navigation";
import { useEffect, useState } from "react";
import queryString from "query-string";
const SearchInput = () => {
const router = useRouter();
const [value, setValue] = useState<string>("");
const debouncedValue = useDebounce<string>(value, 500);
useEffect(() => {
const quary = {
title: debouncedValue
};
const url = queryString.stringifyUrl({
url: "/search",
query: quary
});
queryString
router.push(url);
}, [debouncedValue, router]);
return (
<Input
placeholder="Search"
value={value}
onChange={(e) => setValue(e.target.value)}
/>
);
}
export default SearchInput;