antonioru/beautiful-react-hooks

useDebouncedCallback doesn't consider its dependencies

Ouverte

#420 ouverte le 29 nov. 2023

 (3 commentaires) (2 réactions) (0 personne assignée)JavaScript (581 forks)batch import
buggood first issuehelp wanted

Métriques du dépôt

Stars
 (8 350 étoiles)
Métriques de merge PR
 (Aucune PR mergée en 30 j)

Description

Describe the bug

This is the same issue reported in #386 for useDebouncedCallback, I don't know why that issue has been closed. I'd expect that any dependency given as args will invalidate the callback but that's not the case because deps are not given to the useEffect call here. As result the callback sees the values as one step behind.

To Reproduce

Here's a codesandbox to reproduce the issue https://codesandbox.io/p/sandbox/pedantic-grass-f9f6qw

Expected behavior

When I click on useDebouncedCallback button I should see same values as other buttons in console, but I see the old counter value.

Screenshots

image

Guide contributeur