Back to articles
You Don't Need Redux: Zustand + TanStack Query Replaced 90% of My State Management

You Don't Need Redux: Zustand + TanStack Query Replaced 90% of My State Management

via Dev.to ReactDevForge Templates

Every React project I built between 2019 and 2023 started the same way: install Redux Toolkit, create a store, write slices for auth, write slices for UI state, write slices for API data, write thunks to fetch that API data, write selectors to read it back out. Hundreds of lines of boilerplate before a single feature was done. Then I looked at what those slices actually contained. Most of them were just caching server responses. A usersSlice that fetched users from the API and stored them. An ordersSlice that did the same. Loading states, error states, stale data checks -- all reinvented per slice. That's when it clicked: 70-80% of what I called "state" was actually server data. And Redux is the wrong tool for server data. The Two Kinds of State Client state and server state have fundamentally different problems. Server state is data that lives on your backend. It's async, it can become stale, other users can change it, and you need strategies for caching, refetching, and invalidation.

Continue reading on Dev.to React

Opens in a new tab

Read Full Article
5 views

Related Articles