-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAddPost.tsx
44 lines (38 loc) · 1.08 KB
/
AddPost.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
35
36
37
38
39
40
41
42
43
44
"use client";
import React from "react";
type Props = {
savePost: (e: React.FormEvent, formData: IPost) => void;
};
const AddPost: React.FC<Props> = ({ savePost }) => {
const [formData, setFormData] = React.useState<IPost>();
const handleForm = (e: React.FormEvent<HTMLInputElement>): void => {
setFormData(
(prevState) =>
({
...prevState,
[e.currentTarget?.id]: e.currentTarget?.value,
} as IPost)
);
};
return (
<form className="Form" onSubmit={(e) => savePost(e, formData as IPost)}>
<div>
<div className="Form--field">
<label htmlFor="name">Title</label>
<input onChange={handleForm} type="text" id="title" />
</div>
<div className="Form--field">
<label htmlFor="body">Description</label>
<input onChange={handleForm} type="text" id="body" />
</div>
</div>
<button
className="Form__button"
disabled={formData === undefined ? true : false}
>
Add Post
</button>
</form>
);
};
export default AddPost;