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);

Explanation

Selecting the stable actions object returns the same reference every time. Exposing custom hooks also hides the store shape from components.

Further reading

Problem with a question

State Management · Middle · question 60

Test yourself

Take the State Management · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz