Last active
February 27, 2021 22:38
-
-
Save destinio/fec30a88fc136c7e3c4a182d4a60d421 to your computer and use it in GitHub Desktop.
AppContext
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 React, { createContext, useContext, useReducer} from 'react' | |
const AppContext = createContext() | |
export function useAppContext() { | |
return useContext(AppContext) | |
} | |
const initState = { | |
users: [] | |
} | |
function appReducer(state, action) { | |
switch (action.type) { | |
default: | |
return state | |
} | |
} | |
export default function AppContextProvider({children}) { | |
const [state, dispatch] = useReducer(appReducer, initState) | |
return <AppContext.Provider value={{ state, dispatch }}>{children}</AppContext.Provider> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment