@fetch-suit/react-fetch-interceptor
Version:
a very simple fetch interception solution for react
17 lines (16 loc) • 828 B
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
import { FetchContext } from './context.js';
import { useContext } from 'react';
import { applyInterceptors } from '@fetch-suit/fetch-interceptor';
export function FetchInterceptor(props) {
const { children, interceptors: _interceptors } = props;
const interceptors = Array.isArray(_interceptors) ? _interceptors : [_interceptors];
const fetch = useContext(FetchContext);
const newFetch = applyInterceptors(fetch, ...interceptors);
return (_jsx(FetchContext.Provider, Object.assign({ value: newFetch }, { children: children })));
}
export function createInterceptorComponent(interceptors) {
return function Interceptor(props) {
return (_jsx(FetchInterceptor, Object.assign({ interceptors: interceptors }, { children: props.children })));
};
}