У меня проблемы с определением типов для возвращаемого типа ловушки контекста, значение которого является типом возврата ловушки useReducer.
export const StateContext = createContext([{}]); // How to define the defaultValue here
export const StateProvider = ({ reducer, initialState, children }: {reducer: any, initialState: IStore, children: React.ReactNode }) => (
<StateContext.Provider
value={useReducer<React.Reducer<IStore, IAction>>(reducer, initialState)}>
{children}
</StateContext.Provider>
);
export const useStateValue = () => useContext(StateContext);
Это будет использоваться следующим образом:
const [store, dispatch] = useStateValue();
Я не могу определить тип для createContext