ItSolutionStuff.com

React Axios Delete Request Example

By Hardik Savani • September 5, 2020
React JS

In this example, i will show you react axios delete request example. I’m going to show you about axios delete request in react js. I’m going to show you about axios delete request example react js. you'll learn http delete request in react js.

If you want to learn how to send http delete request with react then i will help you step by step instruction for sending http request using axios react. i will give you very simple example to send http delete request using axios and react.

Axios is a npm package and the provide to make http request from your application. in this example we will use "jsonplaceholder" api to delete data using axios package.

So, let's see bellow example code and preview:

Preview:

Example Code:

import React from 'react';

import axios from 'axios';

export default class PostList extends React.Component {

state = {

posts: []

}

componentDidMount() {

axios.get(`https://jsonplaceholder.typicode.com/posts`)

.then(res => {

const posts = res.data;

this.setState({ posts });

})

}

deleteRow(id, e){

axios.delete(`https://jsonplaceholder.typicode.com/posts/${id}`)

.then(res => {

console.log(res);

console.log(res.data);

const posts = this.state.posts.filter(item => item.id !== id);

this.setState({ posts });

})

}

render() {

return (

<div>

<h1>React Axios Delete Request Example - ItSolutionStuff.com</h1>

<table className="table table-bordered">

<thead>

<tr>

<th>ID</th>

<th>Title</th>

<th>Body</th>

<th>Action</th>

</tr>

</thead>

<tbody>

{this.state.posts.map((post) => (

<tr>

<td>{post.id}</td>

<td>{post.title}</td>

<td>{post.body}</td>

<td>

<button className="btn btn-danger" onClick={(e) => this.deleteRow(post.id, e)}>Delete</button>

</td>

</tr>

))}

</tbody>

</table>

</div>

)

}

}

I hope it can help you...

Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

šŸ“ŗ Subscribe on YouTube

We Are Recommending You

ā˜…

React Axios Get Request Example

Read Now →
ā˜…

Username and Password Validation in React Example

Read Now →
ā˜…

Password and Confirm Password Validation in React

Read Now →
ā˜…

React Form Validation Tutorial Example

Read Now →
ā˜…

React Radio Button onchange | React Radio Button Example

Read Now →
ā˜…

React Select Dropdown onchange | React Select Box Example

Read Now →
ā˜…

How to Create Custom Component in React?

Read Now →
ā˜…

React Switch Case Statement Example

Read Now →
ā˜…

React Bootstrap Collapse Example

Read Now →