Last active
October 10, 2022 07:00
-
-
Save E-fais/ec01a0ce86a9dec2cea2be3ca2cdb060 to your computer and use it in GitHub Desktop.
useContext bug.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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