Lesson 21 — Context
Share data without passing props
Prop drilling means passing a prop through many components that do not use it, just to reach a deep child. Context avoids it: createContext(defaultValue) makes a context, <Ctx.Provider value={…}> supplies a value to everything inside it, and useContext(Ctx) reads it in any child. Components outside every Provider get the default value.
const Lang = createContext("en");
function Hello() { return <p>{useContext(Lang) === "en" ? "Hi" : "Hola"}</p>; }
Why it matters: themes, the logged-in user and language settings usually live in context.
Read the theme with useContext. The preview should show "Theme: dark" (default) and "Theme: light" (inside the Provider).
A quick 3-question quiz on this lesson — instant feedback.
Ready for more? Optional paid resources that pick up where this lesson leaves off.
Some links on this page are affiliate links: we may earn a commission at no extra cost to you. As an Amazon Associate I earn from qualifying purchases.
Project-based React Foundations courses if you want a structured paid path after the free lessons. Wait for a sale — prices drop often.
Browse on Udemy →Search Amazon for React Foundations books — check the publication year so the examples match current versions.
Search Amazon →