State Management · Junior · Question 34 of 75
How do you read just one field from a Zustand store?
const useStore = create((set) => ({ count: 0, user: null, inc: () => {} }));- ✓Correct answer:
const count = useStore((s) => s.count) - 2
const { count } = useContext(useStore) - 3
const count = useStore.count
Explanation
A selector subscribes the component only to count: changes to user won't re-render it. Calling useStore() without a selector subscribes to the whole store and re-renders on any change.