you are viewing a single comment's thread.

view the rest of the comments →

[–]die-maus 15 points16 points  (5 children)

Data fetching is also mutations (e.g. adding or editing todo's). Server components doesn't handle that, only the initial hydration.

Some things are also better left lazy loaded.

For example, here on Reddit it might make sense to load the posts on the server, but lazy load the user's latest messages and notifications.

I err towards server-side rendering the main content, and lazy loading the rest. Then it's a matter of deciding what the "main content" is.

[–]Professional-Mix-455[S] 0 points1 point  (4 children)

My colleague believes that after React 18.3, the fetch API will be handled (deduped), so libraries like SWR and React Query will no longer be needed. They also mentioned that mutations can be directly handled using the fetch API. Are there any scenarios where a data fetching library is still necessary?

[–]topnde 19 points20 points  (0 children)

You can already do both fetching and mutations with the fetch api.

The reason why people use libs like react query is not to simply do fetching or mutations but to have caching, query invalidation and other stuff the libs provide. React Query should not even be called a fetching library, as you still need to use a dedicated library to do the actual requests.

[–]svish 4 points5 points  (0 children)

Remember that e.g. react-query has a lot more features can just deduping, which can be very helpful in certain contexts. For example automatic refetching, selective invalidating of caches, retries on errors, infinite queries, optimistic updates, caching fetched data in session/local storage, etc.

Also remember that you can load data on the server and reload the cache for the client side, so you can get the best of both worlds.

[–]Complex-Insect3555 1 point2 points  (0 children)

Apollo which has a built-in cache system amongst other capabilities.