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 'use-axios-hooks'
✗ import useAxios from 'use-axios-hooks'
Named export, not default. Do not use default import.
useAxiosRetry
✓ import { useAxiosRetry } from 'use-axios-hooks'
✗ const useAxiosRetry = require('use-axios-hooks').useAxiosRetry
CommonJS require is supported but named export in ESM.
useAxiosInterval
✓ import { useAxiosInterval } from 'use-axios-hooks'
Named export for polling functionality.
Demonstrates basic usage of useAxios with loading, error, and cancel states.
import React from 'react';
import { useAxios } from 'use-axios-hooks';
function App() {
const [{ data, isLoading, error, isCanceled }, cancel] = useAxios('https://api.example.com/data');
if (isLoading) return <div>Loading...</div>;
if (error) return <div>Error: {error.message}</div>;
if (isCanceled) return <div>Request canceled</div>;
return (
<div>
<pre>{JSON.stringify(data, null, 2)}</pre>
<button onClick={cancel}>Cancel</button>
</div>
);
}
export default App;
Debug
Known issues
gotchaThe hook does not update when the URL changes; you must remount the component or use a key prop.fixUse a key prop on the component that changes with the URL, or use axios directly with useEffect.
affects: <=1.0.4
breakingAxios peer dependency is version 0.19.0; using Axios 0.21+ may cause compatibility issues.fixInstall axios@0.19.0 or check library updates.
affects: >=0.19.0 <0.21.0
gotchaThe cancel function may not work after component unmount if not used carefully.fixCall cancel in useEffect cleanup to avoid memory leaks.
affects: <=1.0.4
deprecatedThe library uses class components in examples; hooks are the intended pattern.fixUse functional components with hooks as shown in the README.
affects: <=1.0.4
Errors
Common errors & fixes
TypeError: (0 , _useAxiosHooks.useAxios) is not a function
Using default import instead of named import.
fixChange to: import { useAxios } from 'use-axios-hooks' Could not find module 'use-axios-hooks'
Missing installation of the package.
fixRun: npm install use-axios-hooks axios
Invalid hook call. Hooks can only be called inside of the body of a function component.
Calling useAxios outside of a React functional component.
fixMove the hook call inside a functional component.
Audit
Dependencies
reactrequiredpeer dependency required for hooks
axiosrequiredpeer dependency, the underlying HTTP client