📌  相关文章
📜  如何在 reducer 中更新对象的特定键 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:00.256000             🧑  作者: Mango

代码示例1
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 
         }
}