Skip to content

todo item 刪完就不能再新增了 #8

Open

Description

@leo424y

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

Activity

  1. shiningjason commented on Aug 12, 2016

    @shiningjason
    Owner

    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 }

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

  2. self-assigned this
    on Aug 12, 2016
  3. leo424y commented on Aug 12, 2016

    @leo424y
    Author

    感謝您,問題已解

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions