在useContext中使用useReducer

时间:2020-03-22 13:27:17

标签: reactjs

该代码以前曾经运行过,但是现在我遇到了“钩子规则”错误。

我想念什么?

import React, { createContext, useReducer } from 'react';

import initialState from './initialState';
import reducer from './reducer';
import actions from './actions';

const uiContext = createContext();

const uiProvider = ({ children }) => {
  const [state, dispatch] = useReducer(reducer, initialState);
  return (
      <uiContext.Provider
        value={{ state, actions: actions(dispatch) }}
        children={children}
      />
  );
};

export { uiContext, uiProvider };

1 个答案:

答案 0 :(得分:0)

Danko的上述评论解决了这个问题。首先用大写字母解决了这个问题,谢谢!