AxiosX Dev
AxiosX is a tiny React hook library for smart Axios requests with built-in:
- Token auth & request interceptors
- Retry logic & cancellation
- Clean React state:
status
, isLoading
, data
, error
- Supports GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS
🚀 Install
npm install axiosx-dev axios react
✅ Quick Start
import { init, useGet, usePost } from 'axiosx-dev';
init({
baseURL: 'https://api.example.com',
withAuth: true,
tokenKey: 'token',
maxRetries: 2,
retryDelay: 500,
on401: (err) => console.warn('Not authorized!', err),
});
const { get, isLoading, data, error, cancelRequest } = useGet();
get('/users');
if (isLoading) console.log('Loading...');
if (error) console.log(error);
✅ Hooks
✅ Examples
useGet
const { get, data, isLoading, status } = useGet();
useEffect(() => {
get('/users');
}, []);
usePost
const { post, data } = usePost();
post('/users', { name: 'John' });
✅ Config Options
baseURL | string | Base URL for the Axios instance. |
timeout | number | Request timeout in milliseconds. |
headers | Record<string, string> | Custom headers to attach to every request. |
withAuth | boolean | Whether to add an Authorization header with a Bearer token. |
tokenKey | string | Key name in localStorage to read the token from. |
getToken | `() => string | null` |
on401 | (error: any) => void | Callback for handling 401 Unauthorized errors. |
onError | (error: any) => void | Global error handler callback for failed requests. |
maxRetries | number | Number of retry attempts for failed requests. |
retryDelay | number | Delay in ms between retry attempts. |
✅ Docs
👉 Full Docs: https://axiosx-dev-docs.vercel.app (free Vercel subdomain)
MIT License.