React Foundations · Composition

Context as its own provider

Context as provider

Context as its own provider

Once you have a context, you still need to hand its value to the components below. The value reaches only the elements inside the wrapper you provide it with. The classic way wraps children in a .Provider:

<ThemeContext.Provider value="dark">
  <Label />
</ThemeContext.Provider>

React 19 lets you render the context object itself as the provider, passing value directly:

<ThemeContext value="dark">
  <Label />
</ThemeContext>

The two forms are equivalent — <ThemeContext> is shorthand for <ThemeContext.Provider>. The new form reads like any other component, so a provider no longer looks different from the elements around it. Nothing about useContext changes at all; only the way the value is supplied.

createContext still takes a default value, used only when no provider is above. useContext(ThemeContext) reads the nearest provider's value, whichever form supplied it.

Your job is to provide a value by rendering the context object directly.

Challenge

A child reads the default theme because nothing provides a value above it. Export an App component from App.jsx that provides the value dark by rendering the context object itself — <ThemeContext value="dark"> — around a child that reads it with useContext into a paragraph.

The Test renders your component and looks for a paragraph reading dark. The starter renders the child with no provider, so it reads the default light and the Test fails. Render the context object as the provider.

App.jsx
import { createContext, useContext } from 'react';
const ThemeContext = createContext('light');
function Label() {
  const theme = useContext(ThemeContext);
  return <p>{theme}</p>;
}
export function App() {
  return <Label />;
}

No test run yet

The Test is hidden. Run it to check the Challenge — you only see the result, never the test source.