DEV Community

Hash
Hash

Posted on

What is React Context?

Definition

Context provides a way to pass data through component tree without having to pass props down manually at every level.

It is designed to share data that can be considered global for a tree of React components.

Benefit

Using context, we can avoid passing props through intermediate elements (aka prevent props drilling)

Where context is not a good solution?

Note: We need to know to apply it sparingly because it makes component reuse more difficult.

Note: If you only want to avoid passing some props through many levels, component composition is often a simpler solution than context.

Use cases

Such as the current authenticated user, theme, or preferred language or even as a global state management

ref

https://reactjs.org/docs/context.html

Top comments (0)