Browse Source
We wait for at least 500ms before actually calculating the margin. This avoids unnecessary API requests when the user rapidly edits the input field.debug-collab-settlement
Thomas Eizinger
3 years ago
2 changed files with 30 additions and 17 deletions
@ -0,0 +1,11 @@ |
|||
import { useEffect } from "react"; |
|||
|
|||
// Copied from: https://stackoverflow.com/a/61127960/2489334
|
|||
export default function useDebouncedEffect(effect: () => void, deps: any[] | undefined, delay: number) { |
|||
return useEffect(() => { |
|||
const handler = setTimeout(() => effect(), delay); |
|||
|
|||
return () => clearTimeout(handler); |
|||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|||
}, [...deps || [], delay]); |
|||
} |
Loading…
Reference in new issue