Isolate domain state
A large application has independent domains with minimal coordination.
Zustand · Const
Zustand supports multiple stores for separate domains, such as bears and fish. Each store remains isolated and can have its own strict TypeScript type.
Multiple Zustand stores are separate store instances for distinct domains. Each store owns its state and actions, preserving isolation and giving TypeScript a strict type boundary between domains.
const useStore = create<Store>()((set) => ({ ... }))| Name | Type | Description |
|---|---|---|
stateCreator | StateCreator<T> | State creator defining one store's initial state and actions. |
A typed Zustand store hook/API for the specified domain.
import { create } from 'zustand'
interface BearState {
bears: number
addBear: () => void
}
interface FishState {
fishes: number
addFish: () => void
}
export const useBearStore = create<BearState>()((set) => ({
bears: 0,
addBear: () => set((state) => ({ bears: state.bears + 1 })),
}))
export const useFishStore = create<FishState>()((set) => ({
fishes: 0,
addFish: () => set((state) => ({ fishes: state.fishes + 1 })),
}))Creates two independently typed stores, each responsible for one domain.
A large application has independent domains with minimal coordination.
Different teams or modules own separate state contracts.
A cohesive state model is too large for one state creator.
The main reason to use multiple stores is to keep unrelated domains isolated. For example, a bear store can manage bears while a fish store manages fish, and each store has its own strict TypeScript type.
Follow-up: When would a single store be preferable? For application-wide global state, the documentation recommends locating it in one store and using slices to divide a large store.
Create each store independently with create, and give each state creator the type for its domain. Components then select state from the relevant store instead of sharing one combined state object.
Follow-up: How can multiple stores be coordinated? Add explicit actions that call the relevant store APIs, or combine related state into one bounded store when atomic coordination is needed.
Multiple stores provide separate state containers, so a bear-specific update cannot accidentally be treated as fish state. This makes domain boundaries explicit and can improve maintainability in larger applications.
Follow-up: What is the alternative for a large but cohesive state model? Use the slices pattern to compose smaller state creators into one bounded store.
createslices patternbounded storeStateCreatorpersist