T
TanStack2y ago
rival-black

useEffect vs router loader

Hi. I am just curious. What is the difference between async calls in useEffect and the router loader?
2 Replies
multiple-amethyst
multiple-amethyst2y ago
The loader gets called, when navigating to the route. The useEffect gets called, after the component on the route has rendered which triggers its call. Also, if you are using defaultPreload='intent', then hovering on the <Link> caches loads the data and caches it. The best experience for data caching in react would have to be Tanstack Query. Which can also be integrated with Router, so data fetching and caching is available throughout the app.
rival-black
rival-blackOP2y ago
You are the best @Sean Cassiere. Thank you again! I will present this in my department. They will probably ask the same question to me. So I will use this response to that question.

Did you find this page helpful?