Skip to content

Commit 2714dac

Browse files
committed
Add useState
1 parent 8d9f60b commit 2714dac

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

react-todos/src/App.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1+
import { useState } from "react";
12
import "./App.css";
23
import TodoTable from "./components/TodoTable";
34

45
function App() {
5-
const todos = [
6+
const seededTodos = [
67
{ rowNumber: 1, rowDescription: "Feed puppy", rowAssigned: "User One" },
78
{ rowNumber: 2, rowDescription: "Water plants", rowAssigned: "User Two" },
89
{ rowNumber: 3, rowDescription: "Make dinner", rowAssigned: "User One" },
910
];
11+
const [todos, setTodos] = useState(seededTodos);
1012

1113
const addTodo = () => {
1214
if (todos.length > 0) {
@@ -15,8 +17,7 @@ function App() {
1517
rowDescription: "New todo",
1618
rowAssigned: "User Three",
1719
};
18-
todos.push(newTodo);
19-
return <TodoTable todos={todos}/>
20+
setTodos(newTodo);
2021
}
2122
};
2223

@@ -25,6 +26,7 @@ function App() {
2526
<div className="card">
2627
<div className="card-header">Your Todo's</div>
2728
<div className="card-body">
29+
<TodoTable todos={todos} />
2830
<button className="btn btn-primary" onClick={addTodo}>
2931
Add New To-Do
3032
</button>

0 commit comments

Comments
 (0)