Troubleshooting
Nothing happens when I dispatch an action
Never mutate reducer arguments
function todos(state = [], action) {
switch (action.type) {
case 'ADD_TODO':
// Wrong! This mutates state
state.push({
text: action.text,
completed: false
})
return state
case 'COMPLETE_TODO':
// Wrong! This mutates state[action.index].
state[action.index].completed = true
return state
default:
return state
}
}Don't forget to call dispatch(action)
dispatch(action)TodoActions.js
TodoActions.jsAddTodo.js
AddTodo.jsAddTodo.js
AddTodo.jsMake sure mapStateToProps is correct
Something else doesn't work
Last updated