mirror of
https://github.com/arthurfiorette/axios-cache-interceptor.git
synced 2025-12-08 17:36:16 +00:00
28 lines
729 B
JavaScript
28 lines
729 B
JavaScript
/* eslint-disable */
|
|
|
|
/*
|
|
* Replace ../../src with axios-cache-interceptor
|
|
*/
|
|
|
|
import Axios from 'axios';
|
|
import { createContext, useContext, useState } from 'react';
|
|
import { setupCache } from '../../src'; // axios-cache-interceptor
|
|
|
|
/** @type {import('react').Context<import('../../src').AxiosCacheInstance>} */
|
|
const AxiosContext = createContext(null);
|
|
|
|
export const useAxios = () => useContext(AxiosContext);
|
|
|
|
export const AxiosProvider = ({ children }) => {
|
|
const [axios] = useState(
|
|
setupCache(
|
|
// Custom instance to prevent conflict with other pieces of code
|
|
Axios.create(),
|
|
// cache config
|
|
{}
|
|
)
|
|
);
|
|
|
|
return <AxiosContext.Provider value={axios}>{children}</AxiosContext.Provider>;
|
|
};
|