123456789101112131415161718192021222324252627 |
- import React, { createContext, useContext, useReducer, Reducer } from 'react';
- import { StateType } from '../store/initialState';
- type IContextProps = [
- StateType,
- ({type}:{type:string}) => void,
- ]
- export const StateContext = createContext({} as IContextProps);
- export const StoreProvider = ({
- reducer,
- initialState,
- children,
- }: {
- reducer: Reducer<any, any>;
- initialState: StateType;
- children: React.ReactNode;
- }) => (
- <StateContext.Provider
- value={useReducer(reducer, initialState)}
- children={children}
- />
- );
- export const useStore = () => useContext(StateContext);
|