Registry / api / use-axios-client

use-axios-client

JSON →
library2.0.0jsnpmunverified

A React hooks library for making Axios requests, providing a simple `useAxios` hook and a `useLazyAxios` hook for manual triggers. Current stable version 2.0.0, ships TypeScript types, requires React 16.8+ and Axios 0.19+. Key differentiator: minimal abstraction over Axios, supports dynamic URLs, request cancellation, and provides loading/error/data states out of the box.

npm install use-axios-client
INSTALL
IMPORT
SIG · USE-AXIOS-CLIENT
U
use-axios-client
apijavascriptv2.0.0
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-client'
const useAxios = require('use-axios-client')
Library is ESM-only; named export, not default.
useLazyAxios
import { useLazyAxios } from 'use-axios-client'
import useLazyAxios from 'use-axios-client'
Named export, not default.
AxiosResponse
import { AxiosResponse } from 'axios'
import { AxiosResponse } from 'use-axios-client'
Types are re-exported by Axios; use-axios-client does not export them.

Minimal React component using useAxios to fetch data from an API with loading, error, and success states.

import React from 'react'; import { useAxios } from 'use-axios-client'; const App = () => { const { data, error, loading } = useAxios({ url: 'https://jsonplaceholder.typicode.com/todos/1', method: 'GET', }); if (loading) return <div>Loading...</div>; if (error) return <div>Error: {error.message}</div>; return <div>Data: {JSON.stringify(data)}</div>; }; export default App;
Debug
Known issues
breakingIn v2.0.0, the return value changed: 'loading' was renamed from 'isLoading' to 'loading'.
fix
Update code to use 'loading' instead of 'isLoading'.
affects: 2.0.0
breakingThe hook no longer accepts an Axios instance as the first argument; instance must be passed via the config object as 'axios' key.
fix
Pass custom Axios instance as part of the config object, e.g., useAxios({ axios: customInstance, url: '...' }).
affects: >=2.0.0
deprecatedThe 'onSuccess' and 'onError' callbacks are deprecated in favor of using useEffect with data/error.
fix
Remove callbacks and use useEffect to react to data/error changes.
affects: >=1.5.0
breakingIn v2.0.0, the 'cancelRequest' function no longer returns a promise; it returns void.
fix
Remove any await from cancelRequest calls.
affects: 2.0.0
gotchaThe library does not support fetching on mount if 'manual' is set to true; it only fires when 'run' is called.
fix
If you need fetch on mount, do not set 'manual: true'.
affects: >=1.0.0
gotchaWhen using TypeScript, the response data type is not inferred automatically; you must specify a generic type parameter.
fix
Use useAxios<MyDataType>({ url: '...' }) to get typed data.
affects: >=2.0.0
Errors
Common errors & fixes
Cannot read properties of undefined (reading 'get')
The library expects an Axios instance, often from a previous version's API where instance was passed directly.
fix
Upgrade to v2.0.0 and pass the Axios instance via config object: { axios: axiosInstance, url: '...' }.
TypeError: (0 , use_axios_client__WEBPACK_IMPORTED_MODULE_0__.useAxios) is not a function
Importing useAxios as default export instead of named export.
fix
Correct import to: import { useAxios } from 'use-axios-client'.
error TS2304: Cannot find name 'AxiosResponse'
Trying to import AxiosResponse from use-axios-client, but it's not exported there.
fix
Import AxiosResponse from 'axios' instead.
Expected 0 arguments, but got 1.
In v2, the hook no longer accepts multiple arguments; all options go in one config object.
fix
Pass all options as a single object to useAxios.
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies
axiosrequiredCore HTTP client, required at runtime
reactrequiredPeer dependency for React hooks
react-domrequiredPeer dependency for React DOM
Agent activity
31 hits · last 30 days
node
26
Amazon
1
Resources
use-axios-client — npm install use-axios-client · libregistry