Hacker News new | ask | show | jobs
by supermatt 979 days ago
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).
4 comments

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.

OOTB offline-first sounds handy. With SWR I had to modify the fetcher to query and store in indexedDB and then later replay to remote, which while not exactly difficult did require some effort.

I guess its worth giving it a spin and see for myself :)

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).
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 :)
I too default to useSWR because the docs are nicer and it is smaller both in scope and size. Never hit any limits.