Now you need to wrap your application with the Provider:
// your imports hereimport{NameContext}from'./context.js'// do react setup stuffReactDOM.render((<NameContext.Provider>
// rest of your app
</NameContext.Provider>),document.getElementById('root')
Now use useContext in your components like this:
importReact,{useContext}from'react'import{NameContext}from'./context.js'constMyComponent=()=>{// now your name is available in the component// and will also work in all other components like this// with just one contextconstname=useContext(NameContext)return<div>{name}</div>}
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
You should create one globalContext and pass that globalContext to your different Components.
Example:
context.js
Now you need to wrap your application with the Provider:
Now use
useContext
in your components like this: