Live data from Hacker News

TanStack Query(a.k.a. React Query) v5 announced

tanstack.com

31–40 of 64 posts

Re: TanStack Query(a.k.a. React Query) v5 announced

#31

I currently use SWR. Is there a reason to choose tanstack query over SWR? A cursory look shows them to be near identical in scope, but tanstack is ~3x the bundled size. AFAICS there isnt anything that SWR doesnt support either OOTB or via minor modification to the fetcher (e.g. cancellable requests).

How are you comparing bundle sizes? I know that the reported size on some sites like Bundlephobia for v5 is bigger than reality:

https://twitter.com/TkDodo/status/1714275314745081895

Re: TanStack Query(a.k.a. React Query) v5 announced

#32
post #26

I've been using React-query on several projects including the v5 on a recent one. On a new project I decided to give a try to RTK (Redux ToolKit), I must say there's not much reason to not use RTK over a lib like react-query. You basically have the same and more, and all the advantages of using react-redux. It felt backward at first to come back to Redux after all this time, but I'm glad I did, and can't recommend it…

Never used RTK, just plain redux. But for me it was always unnecessary ceremony. Most application state is rather simple, once you properly organize it into "real" state and computed values. I think it vastly depends what you use redux for. If you have very complex local state, that is not always in sync with the server, than it may be the right thing to do. For example something like draw.io. But just for fetching/m…

> But for me it was always unnecessary ceremony

that's always the same critic people (including me) have, but RTK moslty solve that

> But just for fetching/mutating server data more or less synchronously

With RTK you can basically have the same simple usage (with better structure IMO), and if needed you have all the power of redux, side-effect, ready to use

Re: TanStack Query(a.k.a. React Query) v5 announced

#34
post #3

Our team is currently debating whether we should adopt react-query or stick with plain old hand-written code around `fetch`. The team used Apollo in another project, so we are quite familiar with a "heavy handed wrapper" around backend requests. But I'm not sure the added complexity of react-query is "worth it". Anyone have experiences to share, either using react-query, a different library or particularly painful me…

In my opinion react query doesn't really add complexity if you just use to "await" your fetches. It even comes with the nice added functionality to refetch everything when refocusing the browser. And some automatic error handling.

Once you need query invalidation it gets really useful.

But it also depends how you use fetch right now. If you do it on per-route basis, than react query might not bring a lot of benefits.

Re: TanStack Query(a.k.a. React Query) v5 announced

#35
post #23

Earlier quoted context omitted.

Unlike Apollo, React Query is pleasant to use. It is more like a small wrapper that gets out of your way.

What don't you like about Apollo? I've used both apollo (for graphql backends) and react query (for rest backends) and find them quite similar.

Writing your own backend for GraphQL doesn't scale. You should stick to no-code solutions that can auto generate graphQL on top of existing APIs. Checkout https://tailcall.run

Re: TanStack Query(a.k.a. React Query) v5 announced

#36

I currently use SWR. Is there a reason to choose tanstack query over SWR? A cursory look shows them to be near identical in scope, but tanstack is ~3x the bundled size. AFAICS there isnt anything that SWR doesnt support either OOTB or via minor modification to the fetcher (e.g. cancellable requests).

There are some nice to have features in React Query off of the shelf, but nothing I’m aware of that can’t be accomplished with SWR if needed. There’s scroll restoration and offline mutations primarily. I’ve never actually needed either of those, and I personally prefer SWR because it’s so lightweight, out of the way, and portable. One thing RQ definitely has over SWR is better dev tools, but I’ve never actually needed or wanted them for either library.

People do seem to prefer RQ generally, maybe because it’s a bit more intuitive and better documented. It might be a better choice for more complex caching and mutating needs. SWR is still so easy and intuitive as it is, so I haven’t seen a reason to prefer RQ by default.

Re: TanStack Query(a.k.a. React Query) v5 announced

#37

I currently use SWR. Is there a reason to choose tanstack query over SWR? A cursory look shows them to be near identical in scope, but tanstack is ~3x the bundled size. AFAICS there isnt anything that SWR doesnt support either OOTB or via minor modification to the fetcher (e.g. cancellable requests).

How are you comparing bundle sizes? I know that the reported size on some sites like Bundlephobia for v5 is bigger than reality: https://twitter.com/TkDodo/status/1714275314745081895

Thats a good point. I checked using the "better" tool (pkg-size.dev) they show on your link and it seems they are actually comparable for the "default" export (but im not sure what that gives me with tanstack query - its effectively everything with SWR).

Re: TanStack Query(a.k.a. React Query) v5 announced

#38
post #28

I currently use SWR. Is there a reason to choose tanstack query over SWR? A cursory look shows them to be near identical in scope, but tanstack is ~3x the bundled size. AFAICS there isnt anything that SWR doesnt support either OOTB or via minor modification to the fetcher (e.g. cancellable requests).

The dev tools of react query did it for me. Much easier to see what's going on. Especially if you are not completely familiar with all the concepts yet. Also I think react query has more options (you may or may not find useful).

There are devtools for SWR, but im not sure how react query ones compare. I will have to try it out i guess :)

Re: TanStack Query(a.k.a. React Query) v5 announced

#39
post #8
post #5

There have been endless discussions about state management in React. React Query solved the most common and most annoying part of state management for me, which was everything that you fetched via the network. The part that remains is straightforward enough with the built-in useState/useReducer. It does take a moment to learn React Query. You should make sure everyone understands how query keys work and uses them cor…

Can you provide examples regarding right/wrong common mistakes you found in use?

First: Realize that React Query isn't a library for fetching data, but a library for caching the fetched data. So think about how you will be invalidating that cache. For us, the rule of thumb was that each fetch to the API should have it's own cache key in React Query.

Second: The data in cached in React Query is effectively globally available, so it comes with all the benefits and pitfalls that globals have. We use Storybook and do not use React Query in the components that have stories, so React Query is only used in the root components of the app.

Re: TanStack Query(a.k.a. React Query) v5 announced

#40

I've been using React-query on several projects including the v5 on a recent one. On a new project I decided to give a try to RTK (Redux ToolKit), I must say there's not much reason to not use RTK over a lib like react-query. You basically have the same and more, and all the advantages of using react-redux. It felt backward at first to come back to Redux after all this time, but I'm glad I did, and can't recommend it…

Hi, I'm a Redux maintainer. Yeah, Redux Toolkit includes our RTK Query data fetching and caching layer [0] [1], which is roughly equivalent in features and use case to React Query.

In fact, the React Query and Redux maintainers cross-recommend each other's libraries. If you're _not_ using Redux in an app, use React Query for your data fetching. If you _are_ using Redux in an app, use RTK Query for your data fetching.

(There are some differences in features and API design that might be a reason to use RTK Query even if you're not using Redux for client-side state management, such as the OpenAPI/GraphQL codegens, auto-generated React hooks, etc [1] )

[0] https://redux-toolkit.js.org/rtk-query/overview

[1] https://redux.js.org/tutorials/essentials/part-7-rtk-query-b...

[2] https://redux-toolkit.js.org/rtk-query/comparison

Post reply on HN