Home / Learn React / Context: Share Data Without Props Drilling

Context: Share Data Without Props Drilling

Passing props through many layers just to reach a deep child is tiring. Context lets a parent provide a value that any component below it can read directly.

In shortcreateContext, wrap with the Provider, read with useContext. In React 19 you can write <ThemeContext value={...}> as the provider.

Theory in plain words

Context skips the middleThemeButtonuseContextSidebarLayoutFooterApp(provides theme)
Context skips the middle

What it is

Context is a way to make a value available to a whole subtree of components. useContext(MyContext) reads the nearest value provided above.

Why we use it

Some data is needed everywhere: the current user, the theme, the language. Passing it as a prop through ten components ("prop drilling") makes code noisy and fragile.

How it works

You create a context with createContext(default). A parent wraps its children in the context provider with a value. Any descendant that calls useContext gets that value and re-renders when it changes.

Where it is used

  • Theme (light and dark)
  • Logged in user and permissions
  • Language and translations
  • Shopping cart and app settings (often with useReducer)

Theme example

createContext and useContextTry it Yourself

In React 19 you can use the context itself as the provider: <ThemeContext value=...>. Older code writes <ThemeContext.Provider value=...>, which still works.

A user context with a custom hook

Provider component and a hookTry it Yourself
Tip:Use context for values that rarely change. Try composition (passing JSX as children) before reaching for context.

Quick quiz

1. What problem does context solve?

2. Which hook reads a context?

3. When a context value changes, which components re-render?

Common questions

What problem does context solve?

Prop drilling through many layers. Deep children read the value directly.

Which hook reads a context?

useContext. useContext(MyContext).

When a context value changes, which components re-render?

Every component that reads that context. Only readers (and the provider tree parts that re-render for other reasons).