How can Context cause performance problems, and how do you reduce them?
Model answer
When the Provider value changes, every component that reads that context re-renders. If you pass a new object each render, like value={{ user, setUser }}, all consumers update on every parent render.
Fixes: memoise the value with useMemo, split into smaller contexts (state and dispatch separately), keep fast-changing data out of context, or use a store with selectors.
Learn this topic
React Context API Explained: Share Data Without Passing Props in the course React.js Full Course: Beginner to Advanced.
Sign in to add your own answer.