Registry / devops / use-axios-hooks

use-axios-hooks

JSON →
library1.0.4jsnpmunverified

React hooks for making Axios-based network calls with support for retry and polling. Version 1.0.4 is the latest stable release, with maintenance ongoing. Key differentiators: built on top of Axios, simple API with three hooks (useAxios, useAxiosRetry, useAxiosInterval), supports cancellation, retry on failure, and polling. Requires React 16.8.6+ and Axios 0.19.0 as peer dependencies.

npm install use-axios-hooks
INSTALL
IMPORT
SIG · USE-AXIOS-HOOKS
U
use-axios-hooks
devopsjavascriptv1.0.4
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 '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.
fix
Use 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.
fix
Install 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.
fix
Call cancel in useEffect cleanup to avoid memory leaks.
affects: <=1.0.4
deprecatedThe library uses class components in examples; hooks are the intended pattern.
fix
Use 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.
fix
Change to: import { useAxios } from 'use-axios-hooks'
Could not find module 'use-axios-hooks'
Missing installation of the package.
fix
Run: 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.
fix
Move the hook call inside a functional component.
Upgrade
Version history
1.0.4latest on npm
Audit
Dependencies
reactrequiredpeer dependency required for hooks
axiosrequiredpeer dependency, the underlying HTTP client
Agent activity
8 hits · last 30 days
node
8
Resources
use-axios-hooks — npm install use-axios-hooks · libregistry