DEV Community

Sachin
Sachin

Posted on

What is Context In react

Hi we used the context to stop the prop drilling now the question

What is prop drilling

prop drilling is the concept when we data pass the three level of hierarchy
App => card=> user=>date
here in the app component we passed the data in app comp. to card comp. and user comp. and date comp.

What is context

context api is used the managed the stated and share the state across the nested compon.
Image description

Here we see that the we create a context and ok you think like a box and and structute of box i take example on this simple there are some property
you have variable of context in this picture i take the User
Note used value={{youstate,props,function}}

  • Provider

  • consumer

what are state and data you pass the provider you pass the function, data etc
and consumer whose compon used this datac

Now we used the Usecontext hook to used the consuming

What is useContext

use context allow to access the context value provide by a context object direct in the next function component
Image description

Speedy emails, satisfied customers

Postmark Image

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay