Context API is a (kind of) new feature added in version 16.3 of React that allows one to share state across the entire app (or part of it) lightly and with ease.
React.createContext() is all you need. It returns a consumer and a provider. Provider is a component that as it’s names suggests provides the state to its children. It will hold the “store” and be the parent of all the components that might need that store. Consumer as it so happens is a component that consumes and uses the state. More information can be found on React’s documentation page
No. Well, not entirely.
Redux is great and came perfectly to answer the need for state management. Actually, it answered this need so well that it came to be known that you can’t be a “true” React developer if you don’t know your way around Redux. However, Redux has its disadvantages, and that’s why it’s important to know what Context API gives us that Redux doesn’t:
#react #redux #react hooks #api