Created
September 16, 2020 13:19
-
-
Save celsofabri/c84a3b72d294e93e82031998ef885201 to your computer and use it in GitHub Desktop.
Creating a context layer in React App
This file contains 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
import React, { createContext, useState } from 'react'; | |
import initialValues from './initial'; | |
const Context = createContext(initialValues); | |
const GlobalContext = ({ children }) => { | |
const [globalState, setGlobalState] = useState(initialValues); | |
return ( | |
<Context.Provider value={{ globalState, setGlobalState }}> | |
{children} | |
</Context.Provider> | |
); | |
}; | |
export { GlobalContext, Context }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
InitialValues