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:
npm install axios
Axios DELETE request example
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.
import React from 'react'
import axios from 'axios'
const App = () => {
const handleClick = async () => {
const response = await axios
.delete('https://jsonplaceholder.typicode.com/posts/1')
.catch((error) => console.log('Error: ', error));
if (response) {
console.log(response);
}
};
return (
<div>
<button onClick={handleClick}>Click to send DELETE request</button>
</div>
);
};
export default App;
Online runnable example: