How to use the piral-core.useDebounce function in piral-core

To help you get started, we’ve selected a few piral-core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github smapiot / piral / src / packages / piral-search / src / useSearch.ts View on Github external
export function useSearch(): [string, (value: string) => void] {
  const { setSearchInput, triggerSearch } = useActions();
  const searchInput = useGlobalState(m => m.search.input);
  const query = useDebounce(searchInput);
  const cancel = useRef(undefined);

  useEffect(() => {
    cancel.current && cancel.current();
    cancel.current = triggerSearch(query, false);
  }, [query]);

  return [searchInput, setSearchInput];
}