Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
leo424y opened this issue Aug 12, 2016 · 2 comments
Open

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

leo424y opened this issue Aug 12, 2016 · 2 comments
Assignees

Comments

@leo424y
Copy link

leo424y commented Aug 12, 2016

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

@shiningjason
Copy link
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 }

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

@leo424y
Copy link
Author

leo424y commented Aug 12, 2016

感謝您,問題已解

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

No branches or pull requests

2 participants