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?
Had a good experience with RTK Query, lives under redux toolkit but does much more than just reducing the boilerplate for redux which I don't think many people have noticed
I migrated a project to it from react query last year as we liked the react query style hooks and some of its behaviour, but found our usage of react query was getting a bit messy when we started adding dozens and dozens of more endpoints in a large app. Lots of things felt spread out and duplicated, we wanted to centralise things a bit (and simplify the typing) without adding a ton of custom hooks or abstractions
With RTK Query we got to move all the endpoint definitions, cache invalidation behaviour (we had many endpoints that used parameters from many other endpoint responses) and TS definitions to a single place. Also it uses redux underneath so we got the redux tools as well
I'd still use either projects again in the future, just depends on the project
RTK Query felt really good when dealing with a ton of microservices, but maybe overkill if you don't have a ton of endpoints where responses feed into other request parameters
Saw a team trip all over themselves trying to implement the pagination and also introduced a bunch of caching bugs(predictable any time caching is introduced).
It's cool that it's ALSO a general pattern for any async call, but it's really heavy for just that if you don't want the caching and stuff.
Personally I'm just sticking with MobX and more straightforward fetching mechanics.
Best thing you could do, spend some time learning how it works properly (query keys, invalidations... ) and how you'd set up things like pagination.
If at any point anyone goes like "oh it doesn't seem to support this, we'll have to write some wrappers/custom stuff", take a step back and read the docs again or ask around - the library in general takes care of everything it should and gets out of the way really well otherwise.
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.
Mix of both. Some data needs to be ready on page load, but we also have quite a number of interactive use cases (e.g., form validation with a backend query).
I spent a couple of years on a project that used React Query with Axios. The massive advantage over plain fetch was the middleware API. If you want to do things like injecting an auth header or clientside token refresh it's really useful. That was more Axios than React Query though.
I've tried plain fetch + useEffect + useState. It's very easy to mess up the implementation. For example you have to think about what happens if the useEffect triggers again while it is already fetching. For reasons like that, react-query is totally worth it to me.
Looks interesting. Thanks! Not sure how I feel about the key being handed to the fetcher (might be great, might be annoyingly verbose). Will have to see what it looks like in practice. (We are going to use feTS [0] or openapi-fetch [1], which are very particular about how the path is assembled)
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
Anyone have experiences to share, either using react-query, a different library or particularly painful memories _not_ using a comparable library?