$ show simoneb/axios-hooks
axios-hooks is a React library that provides custom hooks for making HTTP requests using axios, with built-in caching, request cancellation, server-side rendering (SSR) support, and configurable defaults. The library exposes a default `useAxios` hook and a `makeUseAxios` factory to create pre-configured instances with custom axios versions, cache implementations, and default options. The hook manages request lifecycle through React's `useReducer`, automatically executes requests on component mount (unless `manual` is true), and supports manual refetch with optional cache usage. It integrates with `lru-cache` for response caching, allowing both client-side caching and SSR hydration via `serializeCache`/`loadCache`. The architecture is a single-component library with a clean API surface. Key entry points are the default export `useAxios` and named exports `configure`, `makeUseAxios`, `loadCache`, `serializeCache`, and `clearCache`. The primary data flow is: component calls `useAxios(config, options)`, which triggers an axios request (with optional cancellation via `AbortController`), stores the response in cache, and updates component state (`loading`, `data`, `error`, `response`). External dependencies are `axios` (peer), `react` (peer), `lru-cache`, and `dequal` for deep equality checks. The library is well-tested with Jest and includes TypeScript type definitions. The code exhibits quality engineering practices: proper use of React hooks (useMemo, useCallback, useRef, useReducer), deep comparison memoization to avoid unnecessary re-renders, abort controller for request cancellation, and a factory pattern (`makeUseAxios`) that enables multiple independent hook instances. The test suite covers edge cases like cancellation, cache behavior, SSR, and option change detection.
The LLM identified 1 files worth highlighting for reuse:
This is the core implementation of the axios-hooks library. It defines the `useAxios` hook, the `makeUseAxios` factory, and supporting functions (`configure`, `loadCache`, `serializeCache`, `clearCache`). The hook manages request state via `useReducer`, handles automatic and manual request execution, integrates an LRU cache for response caching, and uses the AbortController API for request cancellation. The file demonstrates several reusable patterns: a custom deep-comparison memoization hook (`useDeepCompareMemoize`), a reducer pattern for state transitions, a factory for creating configured hook instances, and a caching strategy that persists responses across mounts. This module is self-contained and could be extracted as a standalone hook library for use with any HTTP client, though it is tightly coupled to axios's request configuration format.