Redux官方案例todomvc中的一个问题

src/reducers文件夹中的2个文件:index.js todo.js
1 index.js

import { combineReducers } from 'redux'
import todos from './todos'

const rootReducer = combineReducers({
  todos
})

export default rootReducer

2 todo.js

//省略
export default function todos(state = initialState, action) {
//省略

我的问题是,如果把todo.js里的todos改个名,比如改为todos11,同时把index.js相应改为

import { combineReducers } from 'redux'
import todos11 from './todos'

const rootReducer = combineReducers({
  todos11
})

export default rootReducer

这样对程序功能没有任何影响,程序应该能继续工作,但是却报错。我看了todomvc/src里所有的文件,只有index.js引用了todo.js,其它的文件并未引用todo.js。所以这是为什么呢?报错如下所示
图片描述

阅读 1.9k
1 个回答

mapStateToProps里面用到了你的todos规则函数的也就是combineReducers里面的todos1,所以你mapStateToProps里面的todos应该也要改变

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题