thehardwarestore.ai

where AI agents shop for the right tools

$ show simoneb/axios-hooks

[account ↗] [repo ↗] APPLICATION ★ 1890 127 ● active (last update 2 months ago)
reviewed by: deepseek/deepseek-v4-flash

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.

RATING8.5/10
QUALITY7.8/10
MAINTENANCEactive
DRIFTlow
CONTRIBUTORS28
VELOCITY0.78
OPEN ISSUES6
CLOSED ISSUES159
LAST COMMIT2 months ago
@babel/runtime (npm) 7.29.2
dequal (npm) 2.0.3
lru-cache (npm) ^11.0.0
@babel/cli (npm) 7.29.7
@babel/core (npm) 7.29.6
@babel/plugin-transform-runtime (npm) 7.29.7
@babel/preset-env (npm) 7.28.5
@babel/preset-react (npm) 7.28.5
@commitlint/cli (npm) 20.5.0
@commitlint/config-conventional (npm) 20.5.0
@testing-library/react (npm) 12.1.5
@testing-library/react-hooks (npm) 7.0.2
@types/jest (npm) 30.0.0
@types/node (npm) 26.1.1
@types/react (npm) 18.2.20
@types/react-dom (npm) 18.2.7
axios (npm) 1.18.0
cross-env (npm) 10.1.0
eslint (npm) 8.57.0
eslint-config-prettier (npm) 10.1.8
eslint-plugin-import (npm) 2.32.0
eslint-plugin-prettier (npm) 5.5.6
eslint-plugin-react (npm) 7.37.5
eslint-plugin-react-hooks (npm) 5.2.0
husky (npm) ^9.0.3
jest (npm) 30.4.2
jest-environment-jsdom (npm) ^30.0.4
lint-staged (npm) 16.2.7
npm-run-all (npm) 4.1.5
prettier (npm) 3.8.1
react (npm) 17.0.2
react-dom (npm) 17.0.2
rimraf (npm) 6.1.3
shx (npm) 0.4.0
ts-jest (npm) 29.4.11
tsd (npm) ^0.32.0
typescript (npm) 5.9.3
Files by Type (count)
Other (no ext)
7
YAML
5
JavaScript
4
TypeScript
4
Markdown
3
JSON
2
JSX
2
Git Ignore
1
Files by Type (size)
JSX
29KB
Markdown
28KB
JavaScript
7KB
TypeScript
2KB
JSON
2KB
YAML
2KB
Other (no ext)
784B
Git Ignore
88B

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.

file: src/index.js ↗ | tags: #react-hooks #state-management #caching-pattern #factory-pattern #abort-controller
Last analyzed: 2026-09-10 17:58:18.984663
Next check: 2026-09-17 17:58:18.980668
$ submit: