1

每次调用减速器时,我都会尝试将 10 添加到计数器。我总是收到错误 [未处理的承诺拒绝:TypeError:null 不是对象(评估'state.loaded')]

      var initialState = {
        loaded: 10
      };
      const setRandomArray = (state = initialState, action) => {
      switch (action.type) {
        case "SETARRAY":
          return {
            ...state,
            fbArray: action.fbArray
          };
        case "CLEARARRAY":
          return {
            ...state,
            fbArray: []
          };
        case "VALUETOLOAD":
          return {
            ...state,
            counter: state.loaded + 10
          };

        default:
          return null;
      }
    };

    export default setRandomArray;

我这样称呼减速器:

const getRandomPictures = async () => {
    store.dispatch({ type: "VALUETOLOAD" });
};
4

1 回答 1

3

我认为问题出在您的开关盒上,您的减速器在默认情况下返回 null,这使您的状态对象为 null,尝试返回状态本身。

于 2019-02-21T18:35:34.363 回答