Here’s my take on a lodash.debounce hook. I don’t see why the hook shouldn’t be more convenient to use, so I basically made a useState wrapper which updates the value immediately (a requirement for controlled inputs), and updates a signal, which is meant to be used in a useEffect’s dependency array, only whenever specified as per lodash.debounce’s docs.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Great article!
I've been using this pattern with hooks lately:
It's clean and works well for most of the cases.
Here's a version
useDebounce
implemented using lodash: github.com/gnbaron/use-lodash-debo...Here’s my take on a
lodash.debounce
hook. I don’t see why the hook shouldn’t be more convenient to use, so I basically made auseState
wrapper which updates the value immediately (a requirement for controlled inputs), and updates asignal
, which is meant to be used in auseEffect
’s dependency array, only whenever specified as perlodash.debounce
’s docs.