<NoteState>
components where you want to use this context which you created
</NoteState>
import { createContext } from "react";
const NoteContext = createContext();
export default NoteContext;
import NoteContext from "./NoteContext";
const NoteState = (props)=>{
const user = {
name: "Gourav Khurana",
age: 19,
caast: "General"
}
return (
<NoteContext.Provider value={user}>
{props.children}
</NoteContext.Provider>
)
}
export default NoteState;
This is all about Context API how to create it and add it to Components
Now how to use it in the Components :-
import React, { useContext } from 'react';
import NoteContext from "../contexts/notes/NoteContext";
const About = () => {
const contextValue = useContext(NoteContext);
return (
you can simply use here.
)
}
export default About