robertvari

Delete post example

Apr 12th, 2020
386
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React from 'react';
  2. import './Post_style.css'
  3. import axios from 'axios';
  4.  
  5. function Post(props) {
  6.     const {id, title, body, created} = props.data;
  7.  
  8.     const delete_post = async (event) =>{
  9.         await axios.delete(`http://127.0.0.1:8000/api/posts/${id}/`);
  10.         props.get_posts();
  11.     };
  12.  
  13.     return (
  14.         <div className="post_item">
  15.             <h3>{title}</h3>
  16.             <p>{body}</p>
  17.             <div>{created}</div>
  18.             <button onClick={delete_post}>Delete</button>
  19.         </div>
  20.     );
  21. }
  22.  
  23. export default Post;
Advertisement
Add Comment
Please, Sign In to add comment