Skip to content

Instantly share code, notes, and snippets.

@korayguler
Last active August 13, 2024 23:02
Show Gist options
  • Save korayguler/e7d53350a378c4e7773cbddd8a67ad65 to your computer and use it in GitHub Desktop.
Save korayguler/e7d53350a378c4e7773cbddd8a67ad65 to your computer and use it in GitHub Desktop.
Axios Hook
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