axios-hooks wraps axios in React hooks with optional caching, manual execution, automatic refetch on config changes, and built-in server-side rendering support.
Overview
axios-hooks is a small React library that exposes HTTP calls through a `useAxios` hook while keeping axios as the underlying client. You install it alongside axios as a peer dependency and use a one-line hook signature for typical GET-style data loading.
Returned state includes data, loading, error, and response objects, plus `execute` for manual requests and `manualCancel` to abort in-flight calls. Options control immediate versus manual firing, per-hook caching, SSR participation, and whether pending requests auto-cancel when parameters change.
The package ships helpers to configure global axios instances, LRU-backed response caches, and default hook options. `makeUseAxios` creates isolated hook factories when different APIs or cache policies are needed. `serializeCache` and `loadCache` pass preloaded request results from server render to client hydration.
Hook arguments are compared deeply, so memoize functions in config objects to avoid refetch loops. Testing guidance notes that default caching can leak between tests unless caching is disabled in test setup.
Key features
- useAxios hook around axios
- Built-in SSR cache serialize and load
- Manual and automatic request modes
- LRU response caching
- Global configure and makeUseAxios
- Auto-cancel on config changes
- Deep-equality driven refetching
Use cases
- React data fetching with axios
- SSR apps hydrating API cache
- Deferred POST and PUT submissions
- Multiple APIs via hook instances