useContext

Pascual Vila
Frontend Instructor.
useContext is a Hook that allows you to access context in your functional components. It facilitates data sharing between components without having to manually pass props through each level of the component hierarchy.
useContext example:
{`import React, { createContext, useState, useContext } from "react";
const MyContext = createContext();
function ComponentA() {
const [state, setState] = useState("Initial Value");
return (
);
}
function ComponentB() {
const { state, setState } = useContext(MyContext);
return (
State: {state}
);
}
export default ComponentA;`}