Once server state lives in TanStack Query, what is left is small: the signed-in user, the chosen theme, whether onboarding has been seen, the contents of a cart before it is sent. That is client state - you own it, there is no server copy to reconcile, and it needs to be readable from anywhere.
Zustand is the lightweight option and the one to reach for first. A store is a function returning state and the actions that change it; components subscribe with a selector and re-render only when the selected slice changes. There is no provider to wrap the app in and no boilerplate per action.
Redux Toolkit is the heavier option and still the right one on a large team or a large app. What you get for the ceremony is a strict shape, serialisable actions, excellent devtools and a time-travel debugger - which matters when several people are changing the same state and you need to see exactly what happened.
The mistake worth naming is putting server data into either of them. Copy a fetched list into Zustand and you have taken on cache invalidation, refetching and staleness by hand - the whole problem TanStack Query exists to solve - and the two copies will disagree.
import { create } from 'zustand';
import { persist, createJSONStorage } from 'zustand/middleware';
import AsyncStorage from '@react-native-async-storage/async-storage';
type Theme = 'system' | 'light' | 'dark';
type SettingsState = {
theme: Theme;
hasSeenOnboarding: boolean;
setTheme: (theme: Theme) => void;
completeOnboarding: () => void;
};
// No provider, no reducer file, no action constants.
export const useSettings = create<SettingsState>()(
persist(
(set) => ({
theme: 'system',
hasSeenOnboarding: false,
setTheme: (theme) => set({ theme }),
completeOnboarding: () => set({ hasSeenOnboarding: true }),
}),
{
name: 'settings',
storage: createJSONStorage(() => AsyncStorage),
},
),
);
// In a component: select the ONE field you need. This re-renders when the
// theme changes and not when onboarding does.
function ThemeLabel() {
const theme = useSettings((state) => state.theme);
return <Text>{theme}</Text>;
}
// Actions can be called from outside React too - from a notification
// handler, or a deep link, where there is no component to be inside.
export function resetOnboarding() {
useSettings.setState({ hasSeenOnboarding: false });
}
Open this example in the editor and change it. Nothing you type is saved.