xnimorz/use-debounce

value controller reference changes on every render

Closed this issue · 2 comments

Describe the bug
the reference of value controller object returned by useDebounce keep changing on every render in consumer component. and it cause hooks that use the object as their dependencies to re-call.

Expected behavior
to reference does not change across re-renderes.

use-debounce version: ^7.0.0

Hey @msharifi99
Thanks for the pull request, and I'm sorry for such a long response.

I checked both issue and the pull request.
Original solution suggested to check not the object which you receive, but the definite fieds:

const [value, {cancel}] = useDebounce(123);
...
useEffect(() => {...}, [cancel]);

However, I agree that it may be difficult to support inside each component

I just committed a fix for this: ce543e3

I don't use your PR because it increases the bundle size and this project target is to have a small bundle size and good developer experience at the same time.

Thanks for reporting the issue!

Published in 7.0.1