-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTodoForm.js
More file actions
44 lines (44 loc) · 1.04 KB
/
Copy pathTodoForm.js
File metadata and controls
44 lines (44 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import React, { useState } from "react";
import {
FormGroup,
Input,
InputGroup,
InputGroupAddon,
Button,
Form,
} from "reactstrap";
import { v4 } from "uuid";
export default function TodoForm({ addTodos }) {
const [todoString, setTodoString] = useState("");
const handleSubmit = (e) => {
e.preventDefault();
if (todoString === "") {
return alert("Please Fill Something");
}
const todo = {
todoString,
id: v4(),
};
addTodos(todo);
setTodoString("");
};
return (
<Form onSubmit={handleSubmit}>
<FormGroup>
<InputGroup>
<Input
type="text"
name="todo"
id="todo"
placeholder="Enter a Todo"
value={todoString}
onChange={(e) => setTodoString(e.target.value)}
/>
<InputGroupAddon addonType="prepend">
<Button color="success">Add Todo</Button>
</InputGroupAddon>
</InputGroup>
</FormGroup>
</Form>
);
}