Answers for "how to update specific key of an object in reducer"

0

how to update specific key of an object in reducer

case COMPLETE_TODO: {
  const index = state.todos.findIndex(todo => todo.id === action.payload); //finding index of the item 
  const newArray = [...state.todos]; //making a new array 
  newArray[index].completed = true//changing value in the new array 
  return {   ...state, //copying the orignal state  
          todos: newArray, //reassingning todos to new array 
         }
}
Posted by: Guest on June-09-2021

Code answers related to "how to update specific key of an object in reducer"

Code answers related to "Javascript"

Browse Popular Code Answers by Language