Created
September 28, 2022 14:00
-
-
Save stwgabriel/830345b8c594f69838c30258e3e44d21 to your computer and use it in GitHub Desktop.
useContext base
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
| import { | |
| createContext, | |
| useMemo, | |
| useState, | |
| } from 'react'; | |
| const Context = createContext({}); | |
| function Provider({ children }) { | |
| // States | |
| const [data, setData] = useState(null) | |
| // Provider MEMO | |
| const providerData = useMemo(() => ({ | |
| data, setData, | |
| }), [data]) | |
| return ( | |
| <Context.Provider value={providerData}> | |
| {children} | |
| </Context.Provider> | |
| ) | |
| } | |
| export default Provider; | |
| export { Context }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment