-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTodoForm.js
More file actions
36 lines (29 loc) · 706 Bytes
/
TodoForm.js
File metadata and controls
36 lines (29 loc) · 706 Bytes
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
import React, { useState } from "react";
function TodoForm(props) {
const [input, setInput] = useState("");
const handleSubmit = (e) => {
e.preventDefault();
props.onSubmit({
id: Math.floor(Math.random() * 10000),
text: input,
});
setInput("");
};
const handleChange = (e) => {
setInput(e.target.value);
};
return (
<form className="todo-form" onSubmit={handleSubmit}>
<input
type="text"
placeholder="Add a todo"
value={input}
name="text"
className="todo-input"
onChange={handleChange}
/>
<button className="todo-button"> Add Todo </button>
</form>
);
}
export default TodoForm;