index.js 439 B

12345678910111213141516171819
  1. // contexts/User/index.jsx
  2. import React from "react"
  3. import { reducer, initialState } from "./reducer"
  4. export const UserContext = React.createContext({
  5. state: initialState,
  6. dispatch: () => null
  7. })
  8. export const UserProvider = ({ children }) => {
  9. const [state, dispatch] = React.useReducer(reducer, initialState)
  10. return (
  11. <UserContext.Provider value={[ state, dispatch ]}>
  12. { children }
  13. </UserContext.Provider>
  14. )
  15. }