React Js / APIs / delete data using fetch()
Delete Data
-
1. Step
1. define function
const handleDelete = async () => { const res = await fetch('https://jsonplaceholder.typicode.com/users/1', { method: 'DELETE' }); if (res.ok) { console.log('Deleted successfully'); } else { console.log('Delete failed'); } }; 1. method
2. headers
3. body
2. example
function App() { const handleDelete = async () => { const res = await fetch('https://jsonplaceholder.typicode.com/users/1', { method: 'DELETE' }); if (res.ok) { console.log('Deleted successfully'); } else { console.log('Delete failed'); } }; return ( ); } export default App;
MANVIA BLOG