EN
React - Axios - DELETE request
0 points
In this article, we would like to show you how to make Axios DELETE requests in React.
Note: it is required to add external library to run below example, so use:
xxxxxxxxxx
1npm install axios
In the example below, we use async-await
, but you might as well do it on promises.
Note: we are making a request to jsonplaceholder, so the example will work when you copy it.
xxxxxxxxxx
1
import React from 'react'
2
import axios from 'axios'
3
4
const App = () => {
5
const handleClick = async () => {
6
const response = await axios
7
.delete('https://jsonplaceholder.typicode.com/posts/1')
8
.catch((error) => console.log('Error: ', error));
9
if (response) {
10
console.log(response);
11
}
12
};
13
14
return (
15
<div>
16
<button onClick={handleClick}>Click to send DELETE request</button>
17
</div>
18
);
19
};
20
21
export default App;
Online runnable example: