State Management in 2024: What Actually Works
Redux is no longer the default answer. Compare Zustand, Jotai, TanStack Query, and React's built-in tools to find the right solution for your app.
The State Management Landscape Has Changed
In 2019, the answer to "how do I manage state?" was almost always Redux. In 2024, the answer is "it depends" — and that's a good thing.
Categorize Your State First
| Type | Examples | Best Tool |
|---|---|---|
| Server state | API data, user profile | TanStack Query |
| UI state | modal open, selected tab | useState / useReducer |
| Global UI state | theme, sidebar | Zustand / Context |
| Form state | input values, validation | React Hook Form |
| URL state | filters, pagination | URL params |
TanStack Query for Server State
import { useQuery, useMutation } from "@tanstack/react-query";
function ArticleList() {
const { data, isLoading, error } = useQuery({
queryKey: ["articles", { locale: "en" }],
queryFn: () => fetchArticles("en"),
staleTime: 5 * 60 * 1000, // 5 minutes
});
const { mutate: createArticle } = useMutation({
mutationFn: (data) => api.post("/articles", data),
onSuccess: () => queryClient.invalidateQueries(["articles"]),
});
}
Zustand for Global UI State
import { create } from "zustand";
interface ThemeStore {
dark: boolean;
toggle: () => void;
}
const useTheme = create<ThemeStore>((set) => ({
dark: false,
toggle: () => set((state) => ({ dark: !state.dark })),
}));
// In any component
function ThemeButton() {
const { dark, toggle } = useTheme();
return <button onClick={toggle}>{dark ? "Light" : "Dark"}</button>;
}
When useState Is Enough
Don't reach for a library when the built-in tools work:
// Local UI state — just use useState
const [isOpen, setIsOpen] = useState(false);
// Derived state — just compute it
const filteredPosts = posts.filter(p => p.tags.includes(selectedTag));
The best state management is the least state management. Start simple, add complexity only when you feel the pain.
Written by
Soren Lindqvist
Engineer. Ships the TypeScript, Docker, and database pieces, usually after breaking them in production first.
Related Articles
How to Contribute to Open Source
Your first open source contribution doesn't have to be a major feature. A practical guide to finding projects, making meaningful contributions, and building your reputation.
Next.js App Router: Patterns That Actually Work
Real-world patterns for the Next.js App Router — parallel routes, intercepting routes, loading UI, error boundaries, and streaming with Suspense.
React Server Components Explained
Everything you need to know about React Server Components — what they are, how they differ from client components, and when to use each.