blob: 73ab3544fa25b064260d61069db7420b064da6b8 (
plain) (
blame)
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
|
"use client";
import React, { useEffect } from "react";
import { Input } from "@/components/ui/input";
import { useDoBookmarkSearch } from "@/lib/hooks/bookmark-search";
const SearchInput = React.forwardRef<
HTMLInputElement,
React.HTMLAttributes<HTMLInputElement> & { loading?: boolean }
>(({ className, ...props }, ref) => {
const { debounceSearch, searchQuery, isInSearchPage } = useDoBookmarkSearch();
const [value, setValue] = React.useState(searchQuery);
useEffect(() => {
if (!isInSearchPage) {
setValue("");
}
}, [isInSearchPage]);
const onChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setValue(e.target.value);
debounceSearch(e.target.value);
};
return (
<Input
ref={ref}
value={value}
onChange={onChange}
placeholder="Search"
className={className}
{...props}
/>
);
});
SearchInput.displayName = "SearchInput";
export { SearchInput };
|