Centralize global state
Application-wide client state
Zustand · Const
Zustand recommends keeping an application's global state in a single store. Large stores can be organized with slices while remaining one bounded store.
Keep application-wide state in one Zustand store, creating it with create and exposing state plus update actions through a hook. For larger applications, organize that store into slices while still combining them into one bounded store.
const useStore = create<State>()((set) => ({ ...state, ...actions }))import { create } from 'zustand'
type Store = {
bears: number
addBear: () => void
}
export const useBearStore = create<Store>()((set) => ({
bears: 0,
addBear: () => set((state) => ({ bears: state.bears + 1 })),
}))A single bound store holds the application's global state and exposes actions through one React hook.
Application-wide client state
Large codebases with multiple domains
React components sharing state
The recommended pattern is to place an application's global state in a single Zustand store. A large store can still be divided into slices for organization.
Follow-up: How can a large store remain modular? Use slice creators for separate domains, then combine their results into one bounded store.
Use set or setState for store updates. Zustand uses these APIs to merge the described update and notify listeners correctly.
Follow-up: Why avoid direct mutation? Direct mutation bypasses the store's update path and therefore does not provide the documented merge and listener-notification behavior.
A single store can expose both state and actions through a React hook created with create. Components can select the state they need from that hook.
Follow-up: What if React is not being used? Use the standalone-store API, createStore, which the reference documents as creating a store without React.
createcreateStoresetsetStateslices patterncombine