Skip to content

Instantly share code, notes, and snippets.

@E-fais
Last active October 10, 2022 07:00
Show Gist options
  • Save E-fais/ec01a0ce86a9dec2cea2be3ca2cdb060 to your computer and use it in GitHub Desktop.
Save E-fais/ec01a0ce86a9dec2cea2be3ca2cdb060 to your computer and use it in GitHub Desktop.
useContext bug.
When we use react-browser-router and useContext in a project, there is a chance for getting error.So we need to add a Fragment tag as follows.
app.js
************
function app =()=>{
return(
<GlobalContext.Provider>
<Fragment>
<Routes>
<Route path='/' element={<home.js/>}/>
<Route path='/about' element={<about.js/>}/>
</Routes>
</Fragment>
</GLobalContext.Provider>
)
}
Context.js
**********
import {createContext} from 'react'
export const GlobalContext=createContext()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment