State Management · Senior · Question 18 of 75
How do you react to Zustand changes outside React (e.g. sync to an analytics SDK)?
- ✓Correct answer:
useStore.subscribe(listener)(orsubscribeWithSelectorfor a slice) - 2Poll
getState()withsetInterval - 3It's impossible; subscriptions only work in components
Explanation
subscribe returns an unsubscribe function. The subscribeWithSelector middleware lets you subscribe to a specific selector with an equality function - handy for side effects tied to one field.