React hook for conveniently using the Fetch API. Current stable version is 1.9.5. It is a tiny library (556 B) with both Flow and TypeScript types included. Key differentiators: simple API mirroring fetch, support for custom formatters, error handling with status codes, dependency-based request control (depends array), and a separate usePromise hook for custom async functions. It is actively maintained but has no major releases since 2022.
npm install react-fetch-hookNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows basic usage of useFetch with loading, error, and data states. Includes TypeScript types.
Manually abort the fetch using AbortController in a useEffect cleanup, or use a wrapper library like react-query which handles cancellation.
Use primitive values (booleans, numbers, strings) or memoized objects in the 'depends' array. Consider using useMemo for objects.
Always check response.ok before parsing in the formatter, or use the built-in error handling.
Upgrade to v1.1.0+ and use 'isLoading' instead of 'loading'.
Define an extended Error interface or use (error as any).status.
Replace with: import { useFetch } from 'react-fetch-hook'Ensure the URL is correct, the server supports CORS, and the network is available. Use a try-catch or check the error object from the hook.
Use an AbortController and abort the request in useEffect cleanup, or ignore warnings if acceptable.