react-quick-tutorial icon indicating copy to clipboard operation
react-quick-tutorial copied to clipboard

todo item 刪完就不能再新增了

Open leo424y opened this issue 9 years ago • 2 comments

待辦事項刪到0時,不能再新增,這是因為todo item元件全部移除的關係嗎? 該如何解呢? 感謝您的協助

leo424y avatar Aug 12 '16 02:08 leo424y

Hi @leo424y,

其實前陣子我有發現這個 bug 🐞, 但是一直沒去修它!

問題出現在下面:

const _createTodo = (todos, title) => {
  todos.push({
    id: todos[todos.length - 1].id + 1, // 這裡會爆掉,因為已經沒有上一個 todo 了!
    title,
    completed: false
  });
  return todos;
};

所以你可以修正為

{ id: todos[todos.length - 1] ? (todos[todos.length - 1].id + 1) : 0 }

最後,還是感謝你的回覆! 😀

shiningjason avatar Aug 12 '16 02:08 shiningjason

感謝您,問題已解

leo424y avatar Aug 12 '16 04:08 leo424y