What is React Context?
React Context creates a new data layer apart from virtual DOM, to make states and data easily accessible to all the components. That means if any component wants to access some data, it can subscribe to context and use or update the data as per its requirement. Whenever any state in the context gets updated by any component, all the components that are subscribed to context re-render automatically.
But wait! Why we are using react context? Are states and props not enough to handle data in our project?
What is the use of React Context in React-Redux?
React Context is a feature that React provides us to manage states required in multiple components. Redux is also a state management library and solves the same problem that React Context does but in a different way. In this article, we will see in detail what is react context, why and how to use it, how it is related to and different from react-redux, and then at last we’ll see which one to use and when.
Table of Content
- What is React Context?
- Why to use React Context?
- How to set up React Context?
- How React Context is related to React-Redux?
- What to use and When?