Both @tanstack/react-query and swr are React hooks libraries designed to eliminate boilerplate around server state management—fetching, caching, synchronizing, and updating data from APIs. They solve the same fundamental problem: managing asynchronous data that lives outside your React components, with automatic background refetching, request deduplication, and optimistic updates.
The comparison matters because while both libraries handle typical data-fetching scenarios effectively, they represent different philosophies. SWR prioritizes minimalism and bundle size, backed by Vercel with tight Next.js integration. @tanstack/react-query offers comprehensive features with more configuration power, suited for applications with complex offline requirements or sophisticated caching needs. Developers choosing between them are typically building data-heavy SPAs, dashboards, or Next.js applications where client-side data fetching patterns significantly impact user experience.
Choose @tanstack/react-query when building applications with complex data synchronization requirements, offline functionality, or sophisticated caching needs. The 11KB overhead is justified if you need granular control over cache invalidation, request cancellation, dependent queries, or offline mutation queuing. Its DevTools alone save significant debugging time in data-heavy applications. The larger bundle size pays for itself when your application grows beyond basic CRUD operations.
Choose swr for straightforward data-fetching scenarios where its 5.3KB footprint and minimal API provide everything you need. It's the pragmatic choice for Next.js projects, landing pages, dashboards with simple refresh patterns, or any application where bundle size directly impacts performance metrics. If you're not building offline-first functionality or complex cache orchestration, swr's simplicity means less code to maintain and faster onboarding for team members. The moment you need offline mutations or advanced garbage collection, however, you'll be fighting against its minimalist design.