Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to send axios delete to the backend reactjs

axios.delete(URL, {
  headers: {
    Authorization: authorizationToken
  },
  data: {
    source: source
  }
});
Comment

ReactJS Axios Delete Request Code Example

import React from 'react';  
    
import axios from 'axios';  
    
export default class PostList extends React.Component {  
  state = {  
    photos: []  
  }  
    
  componentDidMount() {  
    axios.get(`https://jsonplaceholder.typicode.com/photos`)  
      .then(res => {  
        const photos = res.data;  
        this.setState({ photos });  
      })  
  }  
    
  deleteRow(id, e){  
    axios.delete(`https://jsonplaceholder.typicode.com/photos/${id}`)  
      .then(res => {  
        console.log(res);  
        console.log(res.data);  
        const photos = this.state.photos.filter(item => item.id !== id);  
        this.setState({ photos });  
      })  
    
  }  
    
  render() {  
    return (  
      <div>  
        <h1> Example of React Axios Delete Request </h1>  
    
        <table className="table table-bordered">  
            <thead>  
              <tr>  
                  <th>ID</th>   
                  <th>Title</th>  
                  <th>Image</th> 
                  <th>Action</th>  
              </tr>  
            </thead>  
    
            <tbody>  
              {this.state.photos.map((photo) => (  
                <tr>  
                  <td>{photo.id}</td>  
                  <td style={{textAlign:"center"}}>{photo.title}</td>  
                  <td><img src={photo.thumbnailUrl}></img></td> 
                  <td>  
                    <button className="btn btn-danger" onClick={(e) =>          this.deleteRow(photo.id, e)}>Delete</button>  
                  </td>  
                </tr>  
              ))}  
            </tbody>  
    
        </table>  
      </div>  
    )  
  }  
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: react-dom and babel cdn 
Javascript :: mongoose response to object 
Javascript :: javascritp canvas 
Javascript :: nodejs read image as base64 
Javascript :: node.js web server 
Javascript :: javascript global object 
Javascript :: draw border on canvas 
Javascript :: search to enter key react 
Javascript :: what is template engine in express 
Javascript :: moment format dd.mm.yyyy 
Javascript :: Is date greater than 18 years old javascript 
Javascript :: react onclick runs on load 
Javascript :: json parse returns object 
Javascript :: exec reges 
Javascript :: javascript stop each loop 
Javascript :: 100vh mobile 
Javascript :: javascript input 
Javascript :: int to string javascript 
Javascript :: javascript image to variable 
Javascript :: delete a label jquer 
Javascript :: js combine 2 array to object key value 
Javascript :: joi validation enum 
Javascript :: babel start command nodejs 
Javascript :: insert element at beginning of array javascript 
Javascript :: react scroll direction 
Javascript :: javascript allow default 
Javascript :: isfunction javascript 
Javascript :: nuxt plugin 
Javascript :: execute command javascript 
Javascript :: slice string js 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =