Published on

Context API .md file

Authors
  • avatar
    Name
    Ganesh Negi
    Twitter

What is Context API ?

Context API is used to pass global variables anywhere in the code without the prop drilling. It helps when there is a need for sharing state between a lot of nested components.

We need to createContext ,it has two properties Provider and Consumer.

The Provider acts as a parent it passes the state to its children and Consumer uses the state that has been passed.

Advantage of using context over React redux ?

In Redux we have to manipulate or update multiple files to add even a single feature but in Context API it can be done in much lesser lines of code.

One way data binding in React is maintained using Context whereas Redux violates it.

Multiple context can be created using Context whereas Redux creates just a single store.