저는 Redux를 처음 사용하고 기본적인 작업을 수행하는 동안 문서를 읽는 중입니다.redux reducer가 상태를 업데이트하지 않습니다.
목록에 항목을 추가 할 수있는 감속기가없는 것 같습니다. 올바른 액션 작성자가 발사하고 있습니다. 제 생각에는 이해가 안되는 제 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;
감사!
전체 코드를 제공 할 수 있습니까? 행동을 어디에서 파견하고 있습니까? 문제를 재현하려했지만 시도 할 수 없습니다. https://codepen.io/olivercs/pen/dWwzpj?editors=0012 –
내 repo는 https://github.com/AntonEmery/react-redux-todo/tree/todo-list-redux/react-app –