Skip to content

Commit 4c53be9

Browse files
committed
Add newTodoForm component
1 parent a65ddaa commit 4c53be9

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

react-todos/src/App.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { useState } from "react";
22
import "./App.css";
3+
import NewTodoForm from "./components/NewTodoForm";
34
import TodoTable from "./components/TodoTable";
45

56
function App() {
@@ -17,7 +18,7 @@ function App() {
1718
rowDescription: "New todo",
1819
rowAssigned: "User Three",
1920
};
20-
setTodos(todos => [...todos, newTodo])
21+
setTodos((todos) => [...todos, newTodo]);
2122
}
2223
};
2324

@@ -27,9 +28,7 @@ function App() {
2728
<div className="card-header">Your Todo's</div>
2829
<div className="card-body">
2930
<TodoTable todos={todos} />
30-
<button className="btn btn-primary" onClick={addTodo}>
31-
Add New To-Do
32-
</button>
31+
<NewTodoForm />
3332
</div>
3433
</div>
3534
</div>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { useState } from "react";
2+
3+
export default function NewTodoForm() {
4+
const [description, setDescription] = useState("");
5+
const [assigned, setAssigned] = useState("");
6+
7+
return (
8+
<div className="mt-5">
9+
<form>
10+
<div className="mb-3">
11+
<label className="form-label">Assigned</label>
12+
<input
13+
type="text"
14+
className="form-control"
15+
required
16+
onChange={(e) => setAssigned(e.target.value)}
17+
value={assigned}
18+
></input>
19+
</div>
20+
<div className="mb-3">
21+
<label className="form-label">Description</label>
22+
<textarea
23+
className="form-control"
24+
row={3}
25+
required
26+
onChange={(e) => setDescription(e.target.value)}
27+
value={description}
28+
/>
29+
</div>
30+
<button type="button" className="btn btn-primary mt-3">
31+
Add ToDo
32+
</button>
33+
</form>
34+
</div>
35+
);
36+
}

0 commit comments

Comments
 (0)