MCPcopy Create free account
hub / github.com/code-with-antonio/nodebase / useEntitySearch

Function useEntitySearch

src/hooks/use-entity-search.tsx:13–54  ·  view source on GitHub ↗
({
  params,
  setParams,
  debounceMs = 500
}: UseEntitySearchProps<T>)

Source from the content-addressed store, hash-verified

11}
12
13export function useEntitySearch<T extends {
14 search: string;
15 page: number;
16}>({
17 params,
18 setParams,
19 debounceMs = 500
20}: UseEntitySearchProps<T>) {
21 const [localSearch, setLocalSearch] = useState(params.search);
22
23 useEffect(() => {
24 if (localSearch === "" && params.search !== "") {
25 setParams({
26 ...params,
27 search: "",
28 page: PAGINATION.DEFAULT_PAGE,
29 });
30 return;
31 }
32
33 const timer = setTimeout(() => {
34 if (localSearch !== params.search) {
35 setParams({
36 ...params,
37 search: localSearch,
38 page: PAGINATION.DEFAULT_PAGE,
39 })
40 }
41 }, debounceMs);
42
43 return () => clearTimeout(timer);
44 }, [localSearch, params, setParams, debounceMs]);
45
46 useEffect(() => {
47 setLocalSearch(params.search)
48 }, [params.search]);
49
50 return {
51 searchValue: localSearch,
52 onSearchChange: setLocalSearch,
53 };
54};

Callers 2

CredentialsSearchFunction · 0.90
WorkflowsSearchFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected