State Management · Middle · Question 7 of 75
A component uses only theme from a big AppContext but re-renders on every cart update. What helps?
- ✓Correct answer: Split the context into smaller ones by domain and change frequency
- 2Wrap the component in
React.memo- it blocks context updates - 3Read the context with
useRefinstead ofuseContext
Explanation
React.memo doesn't stop re-renders caused by a context the component reads. Separate ThemeContext and CartContext limit updates to the consumers that need them. For very frequent updates, use a store with selectors.