0
我有一个connect()ed容器组件,我尝试向我的redux商店写入一个书目列表。动作创造者可以作为道具使用,而状态映射到道具上,但书籍列表永远不会进入到redux存储区。 readingList仍为null,而不是bookArray(动作创建者的传递参数)。有人可以在这里发现问题吗?包括相关的片段在这里:Reducer没有写入Redux存储
import { setReadingList } from '../actions/index';
componentWillMount() {
this.props.setReadingList(bookArray);
}
function mapStateToProps(state) {
return {
readingList: state.readingList
}
}
function mapDispatchToProps(dispatch) {
return bindActionCreators({ setReadingList : setReadingList }, dispatch);
}
export default connect(mapStateToProps, mapDispatchToProps)(ReadingList);
/*-----------*/
./actions/index.js
export function setReadingList(readingList) {
return {
type : "SET_READINGLIST",
payload : readingList
};
}
/*-----------*/
./reducers/index.js
import { combineReducers } from 'redux';
import readingList from './reading_list';
export const rootReducer = combineReducers({
readingList
});
export default rootReducer;
/*-----------*/
./reducers/reading_list.js
export default function(state = null, action) {
switch (action.type) {
case "SET_READINGLIST":
return action.payload;
default:
return state;
}
}
谢谢!
您是否将此减速器组合到您的根减速器中? –