Course contentsShow
← React
Lesson 791 of 2,39621. Context FundamentalsFree lesson

The Provider's value Prop

Passing data through the Provider's value prop which becomes accessible to all consuming components below.

The Provider's value Prop

You'll learn how the value prop on a Context Provider determines what data flows down to all consuming components.


What the value Prop Does

When you wrap components with a Context Provider, the value prop is where you specify exactly what data should be shared. Think of it like a radio station broadcasting a signal—the value prop is the actual content of that broadcast. Every component "tuned in" (consuming the context) will receive whatever you pass through value.

The Provider acts as a gatekeeper: only what you explicitly put in the value prop becomes accessible to consumers below it in the component tree.

How It Works

import { createContext } from 'react';

const ThemeContext = createContext();

function App() {
  return (
    <ThemeContext.Provider value="dark">
      <Header />
      <Main />
    </ThemeContext.Provider>
  );
}

Here, the string "dark" is passed through value. Any component inside <Header /> or <Main /> that consumes ThemeContext will receive "dark".

The value Can Be Anything

You can pass any JavaScript value:

<UserContext.Provider value={{ name: "Alice", role: "admin" }}>
  {children}
</UserContext.Provider>

Now consumers get an object with name and role properties.

Why This Matters

The value prop is your interface for sharing state, functions, or configuration without prop drilling. Change the value, and all consumers automatically see the new data (triggering re-renders where needed).

Key Takeaway: The Provider's value prop is the single source of truth for all data shared through that Context—whatever you pass becomes globally accessible to consuming components below.