Registry / testing / axios-hooks

axios-hooks

JSON →
library5.1.1jsnpmunverified

React hooks for Axios with built-in server-side rendering support. Current stable version is 5.1.1, compatible with axios@1.x. Zero-configuration setup; one-line usage. Released infrequently (last major update 2023). Key differentiators: minimal API surface, automatic request cancellation on unmount, built-in caching and SSR support via serialize/load cache. Comparable to useSWR but specifically for Axios.

npm install axios-hooks
INSTALL
IMPORT
SIG · AXIOS-HOOKS
A
axios-hooks
testingjavascriptv5.1.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

useAxios
import useAxios from 'axios-hooks'
import { useAxios } from 'axios-hooks'
Default export since v1. Named export also available but default is preferred.
configure
import { configure } from 'axios-hooks'
import configure from 'axios-hooks'
Named export, not default.
makeUseAxios
import { makeUseAxios } from 'axios-hooks'
import makeUseAxios from 'axios-hooks'
Named export for creating custom hook instances.
loadCache
import { loadCache } from 'axios-hooks'
import loadCache from 'axios-hooks'
Named export for SSR hydration.

Shows basic usage of useAxios with URL, loading/error states, and refetch.

import useAxios from 'axios-hooks'; function App() { const [{ data, loading, error }, refetch] = useAxios( 'https://reqres.in/api/users?delay=1' ); if (loading) return <p>Loading...</p>; if (error) return <p>Error!</p>; return ( <div> <button onClick={refetch}>refetch</button> <pre>{JSON.stringify(data, null, 2)}</pre> </div> ); }
Debug
Known issues
deprecatedLicense changed to AWISC (Anti War ISC) — may not be OSI-approved
fix
Review license compatibility before use; consider alternatives if license is problematic.
affects: >=5.0.0
breakingaxios-hooks@5.x requires axios@1.x; older versions incompatible
fix
Use axios@1.x or downgrade to axios-hooks@4.x for axios@0.x.
affects: >=5.0.0 <6.0.0
gotchaDefault export useAxios is NOT a named export; incorrectly importing as { useAxios } yields undefined
fix
import useAxios from 'axios-hooks' — no curly braces.
affects: >=1.0.0
gotchauseAxios returns [response, refetch, execute]; third element execute is a function for manual requests, not cancel
fix
Use the third return value for manual execution; cancellation requires axios.CancelToken (legacy) or AbortController (modern).
affects: >=1.0.0
Errors
Common errors & fixes
Uncaught TypeError: (0 , axios_hooks__WEBPACK_IMPORTED_MODULE_0__default) is not a function
Using named import { useAxios } instead of default import.
fix
Change to: import useAxios from 'axios-hooks'
Error: axios-hooks: peer dependency axios not installed
axios is a peer dependency and must be installed separately.
fix
Run: npm install axios
Cannot read properties of undefined (reading 'get')
useAxios invoked without a URL or config argument.
fix
Pass a string URL or an Axios config object as first argument.
Upgrade
Version history
5.1.1latest on npm
Audit
Dependencies
axiosrequiredPeer dependency — core HTTP client used by hooks
reactrequiredPeer dependency — hooks require React 16.8+
Agent activity
21 hits · last 30 days
node
18
OpenAI (training)
1
Resources
axios-hooks — npm install axios-hooks · libregistry