-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuseDataDelete.jsx
More file actions
36 lines (29 loc) · 881 Bytes
/
Copy pathuseDataDelete.jsx
File metadata and controls
36 lines (29 loc) · 881 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/* eslint-disable react-hooks/exhaustive-deps */
/* eslint-disable react-hooks/rules-of-hooks */
import { useState } from "react";
export default function useDeleteData(url, options) {
const opt = options ? options : {}
const [responseData, setResponseData] = useState(null);
const [error, setError] = useState(null);
const [isLoading, setLoading] = useState(false);
const deleteData = async () => {
setLoading(true);
try {
const response = await fetch(url, {
...opt,
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
...opt?.headers,
},
});
const result = await response.json();
setResponseData(result);
} catch (error) {
setError(error);
} finally {
setLoading(false);
}
};
return { responseData, error, isLoading, deleteData };
}