Learn how to implement toggling a todo in a todo list application reducer. let todo = (state = [], action) => { switch(action.type){ case 'ADD_ITEM': return state = [ ...state, { text: action.text, id: action.id, completed: false } ]; case 'TOGGLE_IT…
Learn how to implement adding a todo in a todo list application reducer. let todo = (state = [], action) => { switch(action.type){ case 'ADD_ITEM': return state = [ ...state, { text: action.text, id: action.id, completed: false } ]; default: return s…
/** * A reducer for a single todo * @param state * @param action * @returns {*} */ const todo = ( state, action ) => { switch ( action.type ) { case 'ADD_TODO': return { id: action.id, text: action.text, completed: false }; case 'TOGGLE_TODO': if ( s…
Learn how to create a React todo list application using the reducers we wrote before. /** * A reducer for a single todo * @param state * @param action * @returns {*} */ const todo = ( state, action ) => { switch ( action.type ) { case 'ADD_TODO': ret…
In the previous lesson we created a reducer that can handle two actions, adding a new to-do, and toggling an existing to-do. Right now, the code to update the to-do item or to create a new one is placed right inside of the to-dos reducer. This functi…
/** * A reducer for a single todo * @param state * @param action * @returns {*} */ const todo = ( state, action ) => { switch ( action.type ) { case 'ADD_TODO': return { id: action.id, text: action.text, completed: false }; case 'TOGGLE_TODO': if ( s…
We will learn how to normalize the state shape to ensure data consistency that is important in real-world applications. We currently represent the todos in the state free as an array of todo object. However, in the real app, we probably have more tha…