React · Senior · Question 21 of 75
Why doesn't useContext have "selectors", and how do people work around it?
- ✓Correct answer: Context wakes all consumers; split the context or use an external store
- 2It does: the second argument is
useContext(Ctx, selector) - 3Selectors aren't needed: React compares the fields of the
valueobject itself
Explanation
Any change to value re-renders everyone calling useContext, even if they need one field. Workarounds: several narrow contexts, memoized consumers, the use-context-selector library, or a store with selector subscriptions (Zustand, Redux, Jotai).