Download Easy-Consulting-react/src/context/app-context.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 645 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/f5071caa249115f3b590492f1c8eb471e02aae4b/Easy-Consulting-react/src/context/app-context.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@f5071caa249115f3b590492f1c8eb471e02aae4b/Easy-Consulting-react/src/context/app-context.js
-
curl -L -o app-context.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/f5071caa249115f3b590492f1c8eb471e02aae4b/Easy-Consulting-react/src/context/app-context.js
645 Bytes
| import { useReducer } from "react"; | |
| import { useContext } from "react"; | |
| import { createContext } from "react"; | |
| import { getDecodedUser } from "../component/Login/LoginManager"; | |
| import { reducer } from "./reducer"; | |
| const AppContext = createContext(); | |
| const initialState = { | |
| user: getDecodedUser(), | |
| admin: false, | |
| selectedService: {}, | |
| }; | |
| export const AppProvider = ({ children }) => { | |
| const [state, dispatch] = useReducer(reducer, initialState); | |
| return ( | |
| <AppContext.Provider value={{ state, dispatch }}> | |
| {children} | |
| </AppContext.Provider> | |
| ); | |
| }; | |
| export const useAppContext = () => { | |
| return useContext(AppContext); | |
| }; | |