-
Notifications
You must be signed in to change notification settings - Fork 109
/
Copy pathEditPost.js
42 lines (35 loc) · 1.32 KB
/
EditPost.js
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
import React, { useState } from 'react';
import { useParams } from 'react-router-dom';
import './EditPost.css';
const EditPost = ({data}) => {
const {id} = useParams();
const [post, setPost] = useState({id: null, title: "", author: "", description: ""});
const handleChange = (event) => {
const {name, value} = event.target;
setPost( (prev) => {
return {
...prev,
[name]:value,
}
})
}
return (
<div>
<form>
<label for="title">Title</label> <br />
<input type="text" id="title" name="title" value={post.title} onChange={handleChange} /><br />
<br/>
<label for="author">Author</label><br />
<input type="text" id="author" name="author" value={post.author} onChange={handleChange} /><br />
<br/>
<label for="description">Description</label><br />
<textarea rows="5" cols="50" id="description" name="description" value={post.description} onChange={handleChange} >
</textarea>
<br/>
<input type="submit" value="Submit" />
<button className="deleteButton">Delete</button>
</form>
</div>
)
}
export default EditPost