We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 9010691 commit f084c8cCopy full SHA for f084c8c
react-todos/src/App.js
@@ -12,14 +12,19 @@ function App() {
12
const [todos, setTodos] = useState(seededTodos);
13
14
const addTodo = (description, assigned) => {
15
- if (seededTodos.length > 0) {
16
- const newTodo = {
17
- rowNumber: todos.length + 1,
18
- rowDescription: description,
19
- rowAssigned: assigned,
20
- };
21
- setTodos((todos) => [...todos, newTodo]);
+ let rowNumber = 0;
+
+ if (todos.length > 0) {
+ rowNumber = todos[todos.length - 1].rowNumber + 1;
+ } else {
+ rowNumber = 1;
22
}
+ const newTodo = {
23
+ rowNumber: rowNumber,
24
+ rowDescription: description,
25
+ rowAssigned: assigned,
26
+ };
27
+ setTodos((todos) => [...todos, newTodo]);
28
};
29
30
return (
0 commit comments