useCallback hook and when I always use it

preview_player
Показать описание
In this video I show CONTRIVED (but based on the real-world) example of when I use useCallback while writing my react hooks.

TLDR;
- I always use it when I return a function from custom React hook if it was declared in that hook, since my hook user might decide to put it into dependency array of useEffect which will cause issue shown on the video.

Рекомендации по теме
Комментарии
Автор

that's a lot, why do I need to pass fetchUserDetails in the hook deps in the first place? Can I just avoid putting it there

fra
Автор

In the original useEffect with the problemAuth, you can also do

if (isOnline && !currentUser)

What's your take on this approach vs wrapping a bunch of things in a useCallback?

ekim
Автор

Looks like a React Query problem to me :D

greendsnow
welcome to shbcf.ru