Start adding search page #34

This commit is contained in:
Prayag Prajapati committed 2023-09-27 16:16:50 +05:30
1 parent 4e296bcdb8
commit 18aef998df
9 files changed
+815 -17

No files matched your search

+29
View File
@@ -0,0 +1,29 @@
/** @format */
import { useEffect, useState } from "react";
// see https://github.com/tannerlinsley/react-query/issues/293
// see https://usehooks.com/useDebounce/
export default function useDebounce(value, delay) {
// State and setters for debounced value
const [debouncedValue, setDebouncedValue] = useState(value);
useEffect(
() => {
// Update debounced value after delay
const handler = setTimeout(() => {
setDebouncedValue(value);
}, delay);
// Cancel the timeout if value changes (also on delay change or unmount)
// This is how we prevent debounced value from updating if value is changed ...
// .. within the delay period. Timeout gets cleared and restarted.
return () => {
clearTimeout(handler);
};
},
[value, delay], // Only re-call effect if value or delay changes
);
return debouncedValue;
}