在我的 React ToDo 列表中,重新加载应用程序后,待办事项保持相同的 ID。
因此,如果我开始设置待办事项,它们的 id 将正确编号:0, 1, 2, 3, 4,...
todos: [{id: 0, text: "Create PWA", date: 1601244000000, completed: false},…]
0: {id: 0, text: "Create PWA", date: 1601244000000, completed: false}
1: {id: 1, text: "Use Hooks for Gorilla sound once", date: 1601416800000, completed: false}
...
但是,如果我重新加载,ID 将重置:
todos: [{id: 0, text: "Create PWA", date: 1601244000000, completed: false},…]
0: {id: 0, text: "Create PWA", date: 1601244000000, completed: false}
1: {id: 1, text: "Use Hooks for Gorilla sound once", date: 1601416800000, completed: false}
2: {id: 0, text: "dsadasd", date: 1600812000000, completed: false}
...
任何想法如何解决? 代码沙盒链接