Is this hook intended for debouncing function invocation?
Closed this issue · 3 comments
Hi there! I came across this library trying to find something equivalent to _.debounce
but using React hooks. Something like this:
function Input({ onChange }) {
const handleChange = useDebounce(onChange, 1000);
return (
<input
defaultValue={'Hello'}
onChange={handleChange}
/>
);
}
After looking at the implementation, it seems like it's more like a time-based cache. Do I have that right? It might be useful to provide an example of the more commonly understood (I think?) kind of debouncing if it's possible, or a clarification to specify the intention a little more explicitly otherwise.
Hi, @kmck. Thanks for the issue
Yes, this library provides a time-based cache.
The idea to implement the more commonly understood kind of pattern is good. And I can add it tomorrow.
I'll write here when I cut the new version.
I've just cut the release 0.0.9, with useDebouncedCallback
method. This method is covered with unit tests.
There are examples of usage: React handlers https://codesandbox.io/s/x0jvqrwyq and native events https://codesandbox.io/s/32yqlyo815