Concept
Context makes a value available to every component below a provider without passing it through each level. It suits things many components need: the current user, theme, locale.
The tutor works through these with you, in conversation and code. A session ends when you have shown them, not when a video does.
A few lines that show useContext doing its job.
const ThemeContext = createContext<"light" | "dark">("light");
function App() {
return (
<ThemeContext.Provider value="dark">
<Toolbar />
</ThemeContext.Provider>
);
}
function Toolbar() {
const theme = useContext(ThemeContext);
return <div className={"toolbar-" + theme} />;
}Passing a new object literal as the provider value on every render, value={{ user, theme }}. Every consumer re-renders each time; memoise the value with useMemo.
Your roadmap puts these before useContext, unless you already know them.
Once a session shows you understand useContext, it comes back for review. Each review takes a minute and tells the memory model how well you still know it.
Topics that build on useContext.