DEV Community

Discussion on: 🍦 Cancel Properly HTTP Requests in React Hooks and avoid Memory Leaks 🚨

Collapse
 
viclafouch profile image
Victor de la Fouchardière • Edited

Because I use fetchPosts which is a dependency in my useEffect. But fetchPosts will never updated (it's a useCallback with []as dependency) so useEffect will not be executed a second time.

Collapse
 
sqlrob profile image
Robert Myers • Edited

Right, I understand why it works, but why pick one over the other? Would it be faster to not wrap in useCalllback and use []? This is a fetch, so I guess any savings would be washed away in network.

Thread Thread
 
viclafouch profile image
Victor de la Fouchardière

I want to have a function for getting my data. Maybe in the future I would like to have a button to "refresh" my data. And call "fetchPosts" by clicking on it. Or maybe, for my future pagination by adding page as a new parameter of my function fetchPosts.