State Management · Middle · Question 60 of 75
Why do some teams group Zustand actions into a nested actions object?
const useBearStore = create((set) => ({
bears: 0,
actions: { increase: () => set((s) => ({ bears: s.bears + 1 })) },
}));
export const useBearActions = () => useBearStore((s) => s.actions);- ✓Correct answer: Actions never change, so components can select them all at once without re-rendering on state changes
- 2Zustand requires actions to be nested
- 3It makes actions asynchronous
Explanation
Selecting the stable actions object returns the same reference every time. Exposing custom hooks also hides the store shape from components.