October 2019
Intermediate to advanced
426 pages
11h 49m
English
Next, we are going to define a function for the todo items. Here, we are going to handle the FETCH_TODOS, ADD_TODO, TOGGLE_TODO and REMOVE_TODO actions.
Let's define the todosReducer function now:
function todosReducer (state, action) { switch (action.type) {
case 'FETCH_TODOS': return action.todos
case 'ADD_TODO': const newTodo = { id: generateID(), title: action.title, completed: false } return [ newTodo, ...state ]
Read now
Unlock full access