Create a function that runs only after it stops being called for the given time.
This is custom React hooks, you need to follow the Basic Rules when you use it.
The callback runs once, 400ms after the last click.
const useDebouncedCallback = <A extends unknown[]>(
callback: (...args: A) => void,
wait: number,
) => ((...args: A) => void) & { cancel: () => void }