<Login /> and <Auth />Some sample use cases where the Context API proves helpful are:
the React Context hell is the nasty code you get taking advantage of the React Context API.
How to fix it?
To clean up the nasty code you get from taking advantage of React Context API we need a way to nest multiple Context.Provider without passing them as children of each other.
To achieve that we can use the React.cloneElement API.
The cloneElement API
global state: a global state is a set of local states which are all concurrent with each other
global context: it’s designed to share data that can be considered “global” for a tree of React components, such as the current authenticated user, theme, or preferred language.
provider: Provider React component that allows consuming components to subscribe to context changes.
consumer: A React component that subscribes to context changes. Using this component lets you subscribe to a context within a function component
Role-based access control (RBAC) restricts network access based on a person’s role within an organization and has become one of the main methods for advanced access control.
Some of the designations in an RBAC tool can include:
Cookies are the data stored in the form of key-value pairs that are used to store information about the user on their computer by the websites that the users browse and use it to verify them.
To set or remove the cookies, we are going to use a third-party dependency of react-cookie.
References:
@By Lee Warrick/React’s Context API
@By Gobinda Thakur/Provider Pattern with React Context API
@By Alfredo Salzillo /The React Context hell