by fabian2k on 10/19/23, 10:50 AM
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 correctly. I saw some confusion there when we started using it, and one developer trying to work around stuff manually that React Query does automatically if you properly set up your query keys and invalidate them.
by aj_g on 10/19/23, 11:12 AM
I would almost consider this a default package to use in a react application for server-side state. Any mildly complex UI will almost immediately need init/loading/error/data states, and you begin to write a wrapper that trends towards what react-query gives you. It makes it a lot easier to by default, write code that provides much better UX. The improvement there far outweighs the small amount of time it takes to learn the library and overhead it introduces.
by audessuscest on 10/19/23, 11:27 AM
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 enough. (and the project is still active)
by klauserc on 10/19/23, 10:50 AM
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 memories _not_ using a comparable library?
by supermatt on 10/19/23, 11:21 AM
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).
by zegl on 10/19/23, 10:48 AM
Very nice, and well done team!
I've been using v5 in production since beta 20, and it has been working very reliable for us since then. The documentation for how to upgrade has been a great resource, and a great example of how to do breaking changes in a library as large as this one.
by kebsup on 10/19/23, 12:28 PM
I've seen multiple projects, in which people try to save results of requests into global state using Redux (not rtk), Zustand etc. and I have never seen it done well. React Query and Redux toolkit really should be the default options for request state management.
by phronesis on 10/19/23, 10:50 AM
> Apart from that, we've renamed cacheTime to gcTime to better reflect what it is doing
Does it though? Maybe it's super obvious to more experienced users, but now I need to read the docs to find out what "gc" stands for. Not a big deal, just seems like an unnecessary abbreviation, so I'm curious as to what the reasoning is.
by andrewstuart on 10/19/23, 11:27 AM
My react applications cache nothing and don’t use global state except to put the user Id in localstorage.
No redux, no context, no network cache, no nothing.
Minimal props.
I just use custom events to tell the rest of the application what to.
And use fetch to get stuff.
Does away with all the complexity of state management or prop drilling.
by andy_ppp on 10/19/23, 12:00 PM
It’s worth noting you can autogenerate TanStack Query clients in a typesafe way using graphql-codegen, really saves a lot of time!
by floucky on 10/19/23, 11:23 AM
I love this package, I'm able to remove most of my Redux use cases with it.
by jrogan993 on 10/19/23, 12:53 PM
Best react package ever.
by nsonha on 10/19/23, 11:31 AM
is there a non react equivalent? I wanna vomit every time I see the word "hook" these days.