how to update specific key of an object in reducer

Solutions on MaxInterview for how to update specific key of an object in reducer by the best coders in the world

showing results for - "how to update specific key of an object in reducer"
Sara
14 Jan 2019
1case COMPLETE_TODO: {
2  const index = state.todos.findIndex(todo => todo.id === action.payload); //finding index of the item 
3  const newArray = [...state.todos]; //making a new array 
4  newArray[index].completed = true//changing value in the new array 
5  return {   ...state, //copying the orignal state  
6          todos: newArray, //reassingning todos to new array 
7         }
8}