Replies: 1 comment
-
Because every effect should define an exhaustive list of dependencies. The function is used inside the effect, so it needs to be added as dependency. To achieve referential stability between renders, the function is wrapped in useCallback so that it is only re-created when it’s own dependencies change. See also: https://reactjs.org/docs/hooks-faq.html#is-it-safe-to-omit-functions-from-the-list-of-dependencies |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
https://github.com/tannerlinsley/react-query/blob/69236d3e0bce712376767a86eac9246b304f6be6/examples/pagination/pages/index.js#L39-L43
why useEffect has a dep
fetchProjects
?if i remove
fetchProjects
from useEffect deps and the fetchProjects function can remove useCallback wrapit also stop re render.
Beta Was this translation helpful? Give feedback.
All reactions