鍍金池/ 問答/HTML/ Redux官方案例todomvc中的一個問題

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相應(yīng)改為

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

const rootReducer = combineReducers({
  todos11
})

export default rootReducer

這樣對程序功能沒有任何影響,程序應(yīng)該能繼續(xù)工作,但是卻報錯。我看了todomvc/src里所有的文件,只有index.js引用了todo.js,其它的文件并未引用todo.js。所以這是為什么呢?報錯如下所示
圖片描述

回答
編輯回答
孤酒

mapStateToProps里面用到了你的todos規(guī)則函數(shù)的也就是combineReducers里面的todos1,所以你mapStateToProps里面的todos應(yīng)該也要改變

2018年5月26日 03:20