Skip to content

Instantly share code, notes, and snippets.

@korayguler
Last active March 14, 2023 14:55
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'
type Method = 'get' | 'post' | 'put' | 'delete' | 'patch' | 'head'
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