A React hook for async fetch requests with built-in state management, cancellation, and polling. Current stable version is 0.4.0. Provides a simple, hook-based API for making HTTP requests with auto-fetch on mount, manual triggering, polling, and request cancellation. Ships TypeScript definitions. Key differentiators: minimal API surface, built-in polling, and cancellation via AbortController. Suitable for React 16+ projects needing a lightweight alternative to more complex data-fetching libraries like SWR or React Query.
npm install async-fetchNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows basic usage of the useAsyncFetch hook with buttons for sending and canceling requests.
Pass `{ auto: false }` as the second argument to useAsyncFetch.Use initialData and initialError only for initial values; do not rely on them for reactive updates.
Use only one of `query` or `params` to avoid duplicate query string parameters.
Polyfill AbortController if supporting older browsers (e.g., Internet Explorer).
Set the appropriate parser option (e.g., 'text') or ensure the server returns valid JSON when using the default.
Change import to `import useAsyncFetch from 'async-fetch'` (default import).
Use `const useAsyncFetch = require('async-fetch').default`.Ensure the hook is called inside a valid React component, and that React is installed and imported if using JSX.