Skip to content
Live

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.

By Soren Lindqvist9 min read

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

TypeExamplesBest Tool
Server stateAPI data, user profileTanStack Query
UI statemodal open, selected tabuseState / useReducer
Global UI statetheme, sidebarZustand / Context
Form stateinput values, validationReact Hook Form
URL statefilters, paginationURL 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.

Share

Written by

Soren Lindqvist

Engineer. Ships the TypeScript, Docker, and database pieces, usually after breaking them in production first.

programming

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.

Amara Osei7 min read
nextjs

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.

Soren Lindqvist11 min read
react

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.

Soren Lindqvist8 min read