Context Provider
Question
How do you provide a context value to child components?
Hint
Provider supplies value to all descendant consumers.
Explanation
Create context: const MyContext = createContext(defaultValue). Provide value: <MyContext.Provider value={someValue}>...children...</MyContext.Provider>. All descendant components can consume with useContext(MyContext) or <MyContext.Consumer>. The default value is used only when no Provider is found above. When the provider value changes (new object reference), all consumers re-render. To avoid unnecessary re-renders, memoize the value or split into multiple contexts.
Related Resources
Related Lessons
- useContext
Learn useContext.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.