State Management · Junior · Question 60 of 75
How does a Zustand action read the current state?
const useCart = create((set, get) => ({
items: [],
total: () => get().items.reduce((s, i) => s + i.price, 0),
}));- ✓Correct answer: With the
getfunction passed to the store creator - 2With
this.state - 3With
useContext
Explanation
set updates state and get reads the latest snapshot inside actions. Components should read state through selectors to subscribe to changes.