File size: 942 Bytes
57aa51e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | 'use client';
import {
createContext,
FC,
ReactNode,
useContext,
useRef,
useState,
} from 'react';
import { customFetch, Params } from './custom.fetch.func';
import { useVariables } from '@gitroom/react/helpers/variable.context';
const FetchProvider = createContext(
customFetch(
// @ts-ignore
{
baseUrl: '',
beforeRequest: () => {},
afterRequest: () => {
return true;
},
} as Params
)
);
export const FetchWrapperComponent: FC<Params & { children: ReactNode }> = (
props
) => {
const { children, ...params } = props;
const { isSecured } = useVariables();
// @ts-ignore
const fetchData = useRef(
customFetch(params, undefined, undefined, isSecured)
);
return (
// @ts-ignore
<FetchProvider.Provider value={fetchData.current}>
{children}
</FetchProvider.Provider>
);
};
export const useFetch = () => {
return useContext(FetchProvider);
};
|