axiosx-dev
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

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';

// 1️⃣ Initialize once (e.g. in App.tsx)
init({
  baseURL: 'https://api.example.com',
  withAuth: true,
  tokenKey: 'token',
  maxRetries: 2,
  retryDelay: 500,
  on401: (err) => console.warn('Not authorized!', err),
});

// 2️⃣ Use inside a component
const { get, isLoading, data, error, cancelRequest } = useGet();

get('/users');

if (isLoading) console.log('Loading...');
if (error) console.log(error);

✅ Hooks

Hook HTTP Method Description
useGet GET Performs a GET request.
usePost POST Performs a POST request.
usePut PUT Performs a PUT request.
useDelete DELETE Performs a DELETE request.
usePatch PATCH Performs a PATCH request.
useHead HEAD Performs a HEAD request.
useOptions OPTIONS Performs an OPTIONS request.

✅ Examples

useGet

const { get, data, isLoading, status } = useGet();
useEffect(() => {
  get('/users');
}, []);

usePost

const { post, data } = usePost();
post('/users', { name: 'John' });

✅ Config Options

Option Type Description
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.

Package Sidebar

Install

npm i axiosx-dev

Weekly Downloads

17

Version

1.0.2

License

MIT

Unpacked Size

19.8 kB

Total Files

8

Last publish

Collaborators

  • mesanjeetk