Update dependencies
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import type { AxiosError, AxiosInstance } from "axios";
|
||||
import axios from "axios";
|
||||
import { createContext, useContext, useMemo } from "react";
|
||||
import { createContext, use, useMemo } from "react";
|
||||
import { useToken } from "../token";
|
||||
|
||||
|
||||
@@ -46,8 +46,9 @@ export default function AxiosProvider({
|
||||
}
|
||||
return config;
|
||||
}
|
||||
catch(error){
|
||||
return Promise.reject(error as Error);
|
||||
catch (e) {
|
||||
const error = e as Error;
|
||||
return Promise.reject(error);
|
||||
}
|
||||
});
|
||||
api.interceptors.response.use(r => r, async (error: AxiosError) => {
|
||||
@@ -62,8 +63,9 @@ export default function AxiosProvider({
|
||||
original.headers.Authorization = `Bearer ${newToken}`;
|
||||
return api(original);
|
||||
}
|
||||
catch(refreshError){
|
||||
return Promise.reject(refreshError as Error);
|
||||
catch (e) {
|
||||
const refreshError = e as Error;
|
||||
return Promise.reject(refreshError);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -76,16 +78,16 @@ export default function AxiosProvider({
|
||||
}), [authorizedApi, publicApi]);
|
||||
|
||||
return (
|
||||
<AxiosContext.Provider value={value}>
|
||||
<AxiosContext value={value}>
|
||||
{children}
|
||||
</AxiosContext.Provider>
|
||||
</AxiosContext>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// eslint-disable-next-line react-refresh/only-export-components
|
||||
export function useAxios(){
|
||||
const context = useContext(AxiosContext);
|
||||
const context = use(AxiosContext);
|
||||
|
||||
if(!context){
|
||||
throw new Error("useAxios must be called inside an AxiosProvider");
|
||||
|
||||
Reference in New Issue
Block a user