-
Notifications
You must be signed in to change notification settings - Fork 1
/
AddTodo.tsx
34 lines (29 loc) · 926 Bytes
/
AddTodo.tsx
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
import React, { useState } from 'react'
type Props = {
saveTodo: (e: React.FormEvent, formData: ITodo | any) => void
}
const AddTodo: React.FC<Props> = ({ saveTodo }) => {
const [formData, setFormData] = useState<ITodo | {}>()
const handleForm = (e: React.FormEvent<HTMLInputElement>): void => {
setFormData({
...formData,
[e.currentTarget.id]: e.currentTarget.value,
})
}
return (
<form className='Form' onSubmit={(e) => saveTodo(e, formData)}>
<div>
<div>
<label htmlFor='name'>To-do</label>
<input onChange={handleForm} type='text' id='name' />
</div>
<div>
<label htmlFor='description'>Description</label>
<input onChange={handleForm} type='text' id='description' />
</div>
</div>
<button disabled={formData === undefined ? true: false} >Add</button>
</form>
)
}
export default AddTodo