update useRequest

This commit is contained in:
SrGooglo 2025-05-21 19:11:12 +00:00
parent 7c11af2643
commit 8e26ab1008

View File

@ -8,6 +8,7 @@ export default (method, ...args) => {
if (typeof method !== "function") {
return [() => {}, null, new Error("Method is not a function"), () => {}]
}
const makeRequest = (...newArgs) => {
method(...newArgs)
.then((data) => {
@ -15,6 +16,7 @@ export default (method, ...args) => {
setLoading(false)
})
.catch((err) => {
console.error(err)
setError(err)
setLoading(false)
})
@ -24,8 +26,17 @@ export default (method, ...args) => {
makeRequest(...args)
}, [])
return [loading, result, error, (...newArgs) => {
return [
loading,
result,
error,
(...newArgs) => {
setLoading(true)
makeRequest(...newArgs)
}]
},
() => {
setLoading(true)
makeRequest(...args)
},
]
}