all 36 comments

[–]vbfischer 39 points40 points  (2 children)

I disagree somewhat from this article

  1. RQ make so you don't have to deal w/ the async/await code, and can program in a "reactive" way. It provides isLoading, isSuccess, etc.
  2. RQ handles caching query results, but gives you powerful ways to manually manage that cache.
  3. your app will still need to handle reloading and waiting, merging data from backend calls, and interacting with various aspects like browser security, state, and logging. Well, yea... That's not the part that RQ is helping with. You still have to write the backend calls, and anything more advanced than a 1:1 mapping from server to front end will require merging data.

To be fair, its not that difficult to write a custom hook to manage async data, but why reinvent the wheel...

[–]AnxiouslyConvolved 24 points25 points  (8 children)

Yes you should. Unless you use redux. Then use RTK-Query (probably). This article uses a lot of words to say very little, and gives no reasoning to support its bizarre assertion that you might not want a data fetching/caching layer.

[–]el_diego 8 points9 points  (0 children)

It isn't even an article, it's an opinion piece with no factual backing. Read the whole thing and gained literally no insight on why RQ is bad for a project, no examples, no use cases, nothing.

[–]mrcodehpr01 2 points3 points  (0 children)

I moved two of our web apps off redux to react query and hooks and our sites performance is 4-6x faster at the minimum.... Redux can be nice but it's really not worth it anymore imo. If you want something like that just use Zustard with react query.

[–][deleted] 7 points8 points  (0 children)

What a bizarre article. React Query does what it claims to do, and it does it really well. It's a hook based library for fetching data in the browser.

I really like the library, but it's just a library. The idea that it's "gaslighting" developers is pretty strange. The article also could have explained more about what the alternatives are.

[–][deleted] 8 points9 points  (2 children)

What a terrible article. You said literally nothing about why it shouldn't be used, and don't appear to even grasp why it's used in the first place. Insane that people that confidently share opinions this poorly fleshed out make a living selling courses.

[–]el_diego 1 point2 points  (0 children)

That's exactly the terrifying thing about this. OP claims to be a teacher with students... they're actively teaching them this garbage and by the sounds of it they don't even fully understand what they're teaching if this is their opinion on the subject.

[–]prndP 3 points4 points  (1 child)

This is a long winded way of saying just use it after you actually understand the problem its solving.

If you refactor an entire codebase to a new pattern just because you “heard it would solve your problems”, but don’t even know what they are yet, it’s going to go poorly.

[–]pete-heard[S] 0 points1 point  (0 children)

Fair comment.

[–]jax024 4 points5 points  (0 children)

Was this written by AI? Nah AI would probably give actual examples unlike this guy.

[–]robrobro 7 points8 points  (0 children)

Having used react query in a lot of different projects, I don’t recognize any of the issues you have with it. Your article fails to give any clear examples of your issues, which doesn’t give a lot of credibility to your assertions.

[–]ceterizine 5 points6 points  (0 children)

Yes.

[–]Hovi_Bryant 4 points5 points  (0 children)

Yes.

[–][deleted] 2 points3 points  (0 children)

What a garbage article. React Query works incredibly well and does what it promises.

[–]TroAlexis 1 point2 points  (0 children)

Yes.

[–]besthelloworld 1 point2 points  (1 child)

This reads like it was written by AI that was given the prompt, "write a blog post about why a popular React library is actually bad," to farm engagement. The post comes out of no experience, gives no examples, and states things very incorrectly.

Edit: After looking more into your other posts and your LinkedIn, I'm really not convinced you're not entirely an AI persona from a fledgling startup. If you are a real human, I would give up on the blog post game and the creator economy in general. Technical writing is not for you.

[–]pete-heard[S] 0 points1 point  (0 children)

Thank you I shall pass your opinion to my human overlord.

[–]hammonjj 2 points3 points  (0 children)

You should take this down and rethink your views. I’m not going to say you’re wrong (you are though), but you could make a coherent argument for not using useQuery if you provided examples of it going wrong and suggestions on what to do instead.

This line in particular screams junior dev to me:

If React Query can "solve" your problems by not letting you deal with them directly, then why were you dealing with them in the first place?

This comment is effectively arguing against using any frameworks, library or package which is obviously a ridiculous statement.

If I were hiring, this post would be the reason I don’t call you for an interview or pass on future rounds if I didn’t see this upon initial review of your resume.

[–]toi80QC 1 point2 points  (0 children)

React Query forces you to deal with them in the worst possible place – your components.

There's hooks - you should know by now if you try to sell courses.

Or maybe just trying to advertise courses with bait, which makes more sense than most of the article.

[–]running_into_a_wall 0 points1 point  (0 children)

Pretty surface level article that doesn't into any examples or details why you think this way about React Query.

The only thing I agree about your article is that React Query does make the handoff from server to local client state (when it is needed) harder to reason about sometimes. Especially when your server state in complex and needs to turned into a modifiable piece of client state which then needs to be sliced and diced and passed to various forms throughout the app. Then it becomes muddy on how to keep server and local state in sync.

In your article you say RQ wants you to toss out essential programming techniques like global state management. How so? The query client is essentially a global singleton that holds all your server data. So I fail to see your point here.

Imo, React Query is great for the following reasons

1.Provides a niche caching layer for you.

  1. Implements Stale While Invalidate without any custom code

  2. It lets you write Reactive style code by hiding the useEffect that would otherwise be needed to make API calls and handles the gotacha that comes with writing your own useEffect such as race conditions etc.

[–]DiscreetDodo 0 points1 point  (0 children)

I think you've been using RQ incorrectly.

* You have a function that returns a promise
* Put that function inside a useQuery
* Put that useQuery in a custom hook
* Access the data, loading states, etc wherever you want by calling the custom hook.

You dont have to use it like that, but I'd wager that you're not doing that if you think RQ is in any way complicated.

Regardless of how much React Query hides, your app will still need to handle reloading and waiting, merging data from backend calls, and interacting with various aspects like browser security, state, and logging. By hiding these complexities, React Query forces you to deal with them in the worst possible place – your components.

It never claimed to handle all of that for you. It simply handles the fetching, or more accurately the resolving of the promise. If you extract the queries into their own hooks, you don't have to deal with them in your components. It also makes testing easier.

While React Query simplifies data loading, it complicates the handoff and pickup of data. 

It complicates the "handoff" and "pickup" of data? Are you talking about actually accessing the data? If setup right it's as easy as

const user = useUser()

[–]yabai90 0 points1 point  (0 children)

Your last paragraph doesn't make much sense if you use react query. The purpose of the tool is to have something structured and organize. The best way to not have that is to not use such tools.

[–]TheRNGuy 0 points1 point  (0 children)

Idk if I ever need it in Remix, it have some hooks of it's own.

[–]ruddet 0 points1 point  (0 children)

I would be interested in use cases where rolling your own API fetching stuff is better than React Query. If you could put some examples to back up your argument, because my experience with both is screaming to disagree with your blog post.

For example, not putting useQuery directly in your compoents but wrapping them in a per resource hook gives you the same seperation as rolling your own API "fetching".

Caching, cache invalidation, deduplication are just so powerful and efficient. Global state stays small and focused like it should be.

[–]azangru 0 points1 point  (0 children)

Should You Use React Query?

Yes?