无效的Reducer

时间:2018-04-20 13:59:42

标签: reactjs react-redux

Orignal Error Msg:

  

商店没有有效的减速机。确保参数传递给   combineReducers是一个值为reducers的对象。

以下是: reducer.js

import { combineReducers } from 'redux';
import list_reducer from './reducers/list_reducer.js';


export default combineReducers({
  list_reducer
});

以下是: list_reducer.js

const list_reducer = (state = {
  operation: 'success',
  userlist: []
}, action) => {

  switch (action.type) {
    case "FETCH_USER_FULFILLED":
      return {
        ...state,
        userlist: state.userlist.concat(...action.payload)
      }


    case "UPDATE_USER_DETAILS_FULFILLED":
      return {
        ...state,
        userlist: state.userlist.concat(...action.payload)
      }


    case "DELETE_USER_FULFILLED":
      return {
        ...state,
        userlist: state.userlist.concat(...action.payload)
      }


    case "REGISTER_USER_FULFILLED":
      return {
        ...state,
        userlist: state.userlist.concat(...action.payload)
      }


  }

};

export default list_reducer;

here

尝试了所有事情

现在已经坚持这个错误了很长一段时间而且我在时钟上,所以任何帮助都会受到赞赏。

更新:这里是CONSOLE.LOG(list_reducer)从reducer.js看起来像什么

list_reducer

list_reducer

 function list_reducer() {
    var _state$userlist, _state$userlist2, _state$userlist3, _state$userlist4;

    var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : { operation: 'success', userlist: [] };
    var action = arguments[1];


    switch (action.type) {
        case "FETCH_USER_FULFILLED":
            return Object.assign({}, state, {
                userlist: (_state$userlist = state.userlist).concat.apply(_state$userlist, _toConsumableArray(action.payload))
            });

        case "UPDATE_USER_DETAILS_FULFILLED":
            return Object.assign({}, state, {
                userlist: (_state$userlist2 = state.userlist).concat.apply(_state$userlist2, _toConsumableArray(action.payload))
            });

        case "DELETE_USER_FULFILLED":
            return Object.assign({}, state, {
                userlist: (_state$userlist3 = state.userlist).concat.apply(_state$userlist3, _toConsumableArray(action.payload))
            });

        case "REGISTER_USER_FULFILLED":
            return Object.assign({}, state, {
                userlist: (_state$userlist4 = state.userlist).concat.apply(_state$userlist4, _toConsumableArray(action.payload))
            });

        default:
            return Object.assign({}, state);
    }
}

2 个答案:

答案 0 :(得分:2)

您始终需要在$ which docker-credential-gcloud /Users/moritz/google-cloud-sdk/bin/docker-credential-gcloud 案例中返回state

default

否则,未知操作将导致状态变为default: return state; 。 Redux会检查此情况并引发错误。请记住,所有顶级缩减器都将针对每个操作类型运行,而不仅仅是它具有的情况。阅读the docs中的更多内容。

答案 1 :(得分:1)

实际上,您似乎多次使用combineReducers,这可能会产生此类错误。仔细检查 reducer.js 文件的导入,并检查它是否传递到另一个combineReducer函数。