add function creatPost and login wp
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import { useState } from "react";
|
||||
import { updatePost } from "../wordpress";
|
||||
|
||||
function EditPost({ post }) {
|
||||
const [title, setTitle] = useState(post.title.rendered);
|
||||
const [content, setContent] = useState(post.content.rendered);
|
||||
|
||||
const handleUpdate = async () => {
|
||||
const success = await updatePost(post.id, title, content);
|
||||
if (success) {
|
||||
alert("Article mis à jour !");
|
||||
} else {
|
||||
alert("Échec de la mise à jour.");
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h1>Modifier l’article</h1>
|
||||
<input
|
||||
type="text"
|
||||
value={title}
|
||||
onChange={(e) => setTitle(e.target.value)}
|
||||
/>
|
||||
<textarea
|
||||
value={content}
|
||||
onChange={(e) => setContent(e.target.value)}
|
||||
/>
|
||||
<button onClick={handleUpdate}>Mettre à jour</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default EditPost;
|
||||
Reference in New Issue
Block a user