Context API
Let’s configure the React Context API to handle the authentication data globally in the application.
We'll cover the following...
Context API, a built-in service in React, handles the state globally so that we can access it anywhere in our application. A well-known example of data that needs to be global is the currently authenticated user. Context API helps us easily control what renders to the guest and what is hidden.
Context API configuration
To start configuring the API into the application, we need to initialize an instance of the Context
.
Press + to interact
// frontend/src/context.js// Import the built-in createContext hook from "react"import React, { createContext } from "react";// Create the appliation context, you can name as you like.export const Context = createContext();
Initial state
Then, we need to ...