减速器没有定义

时间:2018-01-05 12:06:46

标签: reactjs redux react-redux

我对react-redux相当新,我收到了这个奇怪的错误。它说我的rootReducer没有定义。 rootReducer是我合并减速器后创建的常量。这是我的代码:

import {combineReducers} from 'redux';
import taskReducer from './handle-action';

rootReducer = combineReducers({
    tasks: taskReducer
});

export default rootReducer;

我错过了什么?

2 个答案:

答案 0 :(得分:2)

您错过了定义rootReducer变量

const rootReducer = combineReducers({ tasks: taskReducer });

export default combineReducers({ tasks: taskReducer });

答案 1 :(得分:1)

无论您导出的是什么,都必须是变量或函数,因此它应该是const or var or let

import {combineReducers} from 'redux';
import taskReducer from './handle-action';

const rootReducer = combineReducers({
    tasks: taskReducer
});

export default rootReducer;