in src/utils.ts [80:102]
export function useValueDebounce<T>(
globalVal: T,
globalSet: (val: T) => void,
): [T, (val: T) => void] {
const [val, set] = React.useState(globalVal);
React.useEffect(() => {
// begins a countdown when 'val' changes. if it changes before countdown
// ends, clear the timeout avoids lodash debounce to avoid stale
// values in globalSet.
if (val !== globalVal) {
const timeout = setTimeout(() => globalSet(val), 250);
return () => clearTimeout(timeout);
}
return void 0;
}, [val]);
React.useEffect(() => {
set(globalVal);
}, [globalVal]);
return [val, set];
}