我对Redux还不熟悉,正在阅读文档,同时试图创建一个基本的待办事项清单。
我似乎无法让我的reducer将一个项添加到列表中。正确的action creator是在触发,我认为可能是我在Object.assign
语句中没有理解的某些问题。下面是我的store.js
文件。
const defaultState = {
todos:[
{
text: 'walk gilbert'
},
{
text: 'cook dinner'
},
{
text: 'clean bathroom'
}
]
}
function todos(state = defaultState) {
return state;
}
function modifyList(state = defaultState, action) {
switch(action.type) {
case 'ADD_TODO':
return Object.assign({}, state, {
todos: [
...state.todos,
{
text: action.text,
}
]
})
default:
return state;
}
}
const rootReducer = combineReducers({todos, modifyList})
const store = createStore(rootReducer, defaultState);
export default store;
谢谢!