A thin fetch wrapper (v0.0.7) providing useful defaults like JSON handling, retry logic, timeout, and error types (HTTPError, ParseError, TimeoutError). Inspired by got. Actively maintained on GitHub with regular updates. Key differentiators: lightweight, no dependencies, ESM and CJS support, bundled for browsers via unpkg, and extensible via createFetch. Unlike ky or node-fetch, it focuses on minimal overhead while adding essential features.
npm install use-fetchNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates basic GET request with JSON parsing and error handling for HTTP and timeout errors.
Access parsed data via response.body.
Set timeout option to a positive number to avoid hanging requests.
Override the methods array in retry option to include POST if needed.
Add a fetch polyfill like unfetch before importing use-fetch.
Polyfill AbortController or use Node.js >= 14.
Do not use new usefetch.HTTPError(); errors are automatically created by usefetch on failed requests.
Check response.status before parsing JSON, or set json: false and parse manually.
Increase timeout value or investigate server response time.
No dependency data recorded yet.