Reducer
Pure Functions
Example
export function addTodo(state, todo){
return {
...state, // We don't mutate the state. We create a copy.
todos: state.todos.concat(todo)
}
}
export function removeTodo(state, todo){
return {
...state, // again.
todos: state.todos.filter((t) => t.id !== todo.id))
}
}Last updated