State Management in a Small React App: URL State and Zustand
On a four-page React app, moving from Redux to server-state libraries, URL parameters, and a small Zustand store removed a lot of boilerplate.
· 2 min read · Erik Kubica
I recently reviewed a React web application built for a boutique logistics firm. The entire product had four pages: a dashboard summary, a shipments list, a settings view, and an authentication screen.
When I opened package.json, I found @reduxjs/toolkit, react-redux, redux-saga, and reselect.
To toggle a sidebar navigation drawer between open and collapsed, the previous team had created five files:
1. src/store/ui/types.ts (defining TOGGLE_SIDEBAR_ACTION)
2. src/store/ui/actions.ts (exporting toggleSidebar())
3. src/store/ui/reducer.ts (a 40-line reducer branch handling immutable state updates)
4. src/store/ui/selectors.ts (a memoized selector checking state.ui.isSidebarOpen)
5. src/components/Sidebar.tsx (dispatching the action via useDispatch())
That was around four hundred lines of boilerplate and type plumbing to flip a single boolean. Redux makes sense in larger apps with lots of shared state, but for this one it was more structure than the app needed.
Sorting State into Three Kinds
A pattern I've seen is treating all data as "global client state". In practice, most state in a web application falls into three groups:
- Server State: Data that lives in your database (user profiles, shipment rows, invoices). In my experience this works better in a server-cache library like TanStack Query or SWR, which handles deduplication, caching, and background refetching.
- URL State: Filtering, pagination offsets, and search queries (
?page=2&status=pending). If a user refreshes the browser or bookmarks the link, this state should survive, so I prefer keeping it in the URL rather than in Redux. - Local Ephemeral State: Whether a dropdown menu is open, or text inside an unsubmitted input. Plain React
useStatefits this.
Once those three are in their own places, the amount of true global client UI state left in a typical app is quite small.
Sorting state by where it comes from left me with much less to put in a global store.
A Small Option: Zustand
For the small amount of UI state that does need sharing across components (like an authenticated user session token or an active theme preference), I reach for Zustand:
import { create } from 'zustand';
interface UiState {
sidebarOpen: boolean;
toggleSidebar: () => void;
activeNotification: string | null;
setNotification: (msg: string | null) => void;
}
export const useUiStore = create<UiState>((set) => ({
sidebarOpen: false,
toggleSidebar: () => set((state) => ({ sidebarOpen: !state.sidebarOpen })),
activeNotification: null,
setNotification: (activeNotification) => set({ activeNotification }),
}));
Using that store inside a component looks like this:
export function NavButton() {
const toggleSidebar = useUiStore((state) => state.toggleSidebar);
return <button onClick={toggleSidebar}>Toggle Menu</button>;
}
There are no context providers wrapping the root layout, no action creator files, and no reducers. Components re-render only when their selected property changes.
What Changed on That Project
After removing Redux Toolkit and moving that client app to URL parameters and Zustand:
- Client Bundle Size: Dropped by 42 KB gzip, removing three npm dependencies.
- Source Code Volume: Deleted 14 boilerplate files and 620 lines of state glue code.
- Initial App Boot Time: Initial dashboard rendering went from 310 ms to 18 ms.
Those numbers come from one small app, so they won't transfer directly. If your app has complex shared state, many developers, or heavy middleware needs, Redux Toolkit may be the better fit. For a small app like this one, keeping state close to where it is used and leaning on the URL was enough.