Last active
August 13, 2024 23:02
-
-
Save korayguler/e7d53350a378c4e7773cbddd8a67ad65 to your computer and use it in GitHub Desktop.
Axios Hook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { AxiosRequestConfig, default as _axios } from 'axios' | |
const instance = _axios.create({}) | |
export const axios = async ({ | |
method, | |
url, | |
data, | |
...rest | |
}: AxiosRequestConfig) => { | |
try { | |
const response = await instance({ | |
method, | |
url, | |
data, | |
...rest, | |
}) | |
return [response.data, null] | |
} catch (error) { | |
return [null, error] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment