A React hook that integrates axios with React Suspense for data fetching inside function component bodies. Version 1.0.0 is stable, uses a simple API mirroring axios parameters, and automatically caches responses globally across components. It offers both a throwing `useAxios` (for use with Suspense and Error Boundaries) and a safer error-handling `useAxiosSafe`, plus a `refetch` function to manually invalidate cached data. Requires React ≥16.8 and `axios` as a peer dependency. Its key differentiator is the Suspense-first design: no manual loading state management, with caching built in.
npm install use-axiosNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Minimal example: useAxios with React Suspense to show a loading fallback while fetching user data.
Wrap the calling component in a <Suspense> with a fallback.
Destructure as [error, { data }].Ensure arguments are stable references or use primitive strings.
Ensure a component using the same URL/config is rendered when calling refetch.
Wrap the component in <Suspense> fallback={...} />.Wrap the component in an ErrorBoundary (e.g., react-error-boundary).
Use `import useAxios from 'use-axios'` (without curly braces).