create-fetch-hooks
Version:
A simple and powerful custom React hook (useApi) that simplifies API requests with automatic loading and error states. Ideal for clean and maintainable data fetching in React components.
11 lines (10 loc) • 437 B
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
import { createContext, useContext, useRef } from "react";
const FetchCacheContext = createContext(null);
export const FetchCacheProvider = ({ children }) => {
const cacheRef = useRef(new Map());
return (
// @ts-ignore
_jsx(FetchCacheContext.Provider, { value: cacheRef.current, children: children }));
};
export const useFetchCache = () => useContext(FetchCacheContext);