04 / 09
Deprecated

What happens if we use context without wrapping the component chain in the provider?

  1. 1

    If a component is not wrapped in the Context.Provider, it will receive the default value that was set when the context was created.

  2. 2

    The provider's job is to override the default values, essentially providing a dependency injection mechanism to the React component tree.

  3. 3

    Remember that in React 19, you dont use .provider syntax, you don't need to type .Provider anymore.

  4. 4

    In React 18 and older, MyContext was just an object, and you had to access a special property on it called .Provider. In React 19, the MyContext object is the provider component.

Old vs New syntax: