State Management · Middle · Question 22 of 75
How do you read or update a Zustand store outside React components (e.g. in an API helper)?
- ✓Correct answer: With
useStore.getState()anduseStore.setState() - 2You can't - the store is available only inside hooks
- 3Through
useContext(useStore)
Explanation
The hook returned by create also carries the vanilla store API: getState, setState, subscribe. Handy for interceptors, websockets and tests.