Reactjs 获取错误“;期望减速器是一个函数;?

Reactjs 获取错误“;期望减速器是一个函数;?,reactjs,redux,react-router,react-redux,Reactjs,Redux,React Router,React Redux,我得到错误“期望减速器是一个函数。” 我试图在我的项目中添加redux。我创建了reducer,但也得到了错误“期望reducer是一个函数”。这是我的代码 上托利面 export default function(state = [], action) { switch (action.type) { case 'ADD_ITEM': return [ ...state, acti

我得到错误“期望减速器是一个函数。”

我试图在我的项目中添加
redux
。我创建了
reducer
,但也得到了错误“期望reducer是一个函数”。这是我的代码

上托利面

export default function(state = [], action) {
    switch (action.type) {
        case 'ADD_ITEM':
            return [
                ...state,
                action.payload
            ];
        case 'DELETE_ITEM':
            const index = state.indexOf(action.payload);
            if (index === -1) {
                return state;
            }
            return state.slice(0, index).concat(state.slice(index + 1));
        case 'UPDATE_ITEM':
            let newList = state.slice()
            newList.splice(action.payload.index, 1, action.payload.item)
            return newList;
        default:
            return state

    }
}

由于您使用的是默认导出(非命名导出),因此减缩器的导入语句不应使用大括号:

import combindReducer from './reducers/index';


你能把
combinedReducer
的代码贴出来吗?是的,我需要看一下
combinedReducer
。合并是打字错误吗?也许你并没有真正导入减速机。等等,我想整个代码都在这里
export default function(state = [], action) {
    switch (action.type) {
        case 'ADD_ITEM':
            return [
                ...state,
                action.payload
            ];
        case 'DELETE_ITEM':
            const index = state.indexOf(action.payload);
            if (index === -1) {
                return state;
            }
            return state.slice(0, index).concat(state.slice(index + 1));
        case 'UPDATE_ITEM':
            let newList = state.slice()
            newList.splice(action.payload.index, 1, action.payload.item)
            return newList;
        default:
            return state

    }
}
import combindReducer from './reducers/index';
import first_redux from './topstories';