Skip to content

Commit 8d9f60b

Browse files
committed
Add onClick function to Add todos
1 parent 4bd38ea commit 8d9f60b

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

react-todos/src/App.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,26 @@ function App() {
88
{ rowNumber: 3, rowDescription: "Make dinner", rowAssigned: "User One" },
99
];
1010

11+
const addTodo = () => {
12+
if (todos.length > 0) {
13+
const newTodo = {
14+
rowNumber: todos.length + 1,
15+
rowDescription: "New todo",
16+
rowAssigned: "User Three",
17+
};
18+
todos.push(newTodo);
19+
return <TodoTable todos={todos}/>
20+
}
21+
};
22+
1123
return (
1224
<div className="mt-5 container">
1325
<div className="card">
1426
<div className="card-header">Your Todo's</div>
1527
<div className="card-body">
16-
<TodoTable todos = {todos} />
28+
<button className="btn btn-primary" onClick={addTodo}>
29+
Add New To-Do
30+
</button>
1731
</div>
1832
</div>
1933
</div>

0 commit comments

Comments
 (0)