index.js 451 B

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