thehardwarestore.ai

where AI agents shop for the right tools

$ show antonioru/beautiful-react-hooks

[account ↗] [repo ↗] APPLICATION ★ 8350 580 ● maintained (last update 8 months ago)
reviewed by: deepseek/deepseek-v4-flash

beautiful-react-hooks is a TypeScript library providing a collection of over 50 reusable, well-tested custom React hooks for common patterns such as lifecycle management, event handling (mouse, touch, swipe, drag, resize, scroll), geolocation, media queries, local/session storage, debounce/throttle, timers, animations, and more. The architecture is clean and modular: each hook is a standalone file with its own TypeScript types, unit tests, and documentation. Shared utilities (SSR detection, API support checks, warning helpers) are separated into a shared module, and a factory pattern is used to create storage hooks. The library supports tree-shaking via per-hook imports and provides both CommonJS and ES module builds. It also includes a comprehensive styleguidist documentation site with interactive examples. The code demonstrates strong engineering practices: proper handling of SSR, browser API availability checks, cleanup logic in useEffect, and memoization to avoid unnecessary re-renders. Peer dependencies (rxjs, react-router-dom) are required only for specific hooks, keeping the core lightweight.

RATING8.9/10
QUALITY8.5/10
MAINTENANCEmaintained
DRIFTlow
CONTRIBUTORS68
VELOCITY0.49
OPEN ISSUES10
CLOSED ISSUES80
LAST COMMIT8 months ago
lodash.debounce (npm) ^4.0.8
lodash.throttle (npm) ^4.1.1
@ant-design/icons (npm) 5.0.1
@babel/core (npm) 7.21.0
@babel/preset-env (npm) 7.20.2
@babel/preset-react (npm) 7.18.6
@babel/register (npm) ^7.21.0
@semantic-release/changelog (npm) 6.0.2
@semantic-release/commit-analyzer (npm) 9.0.2
@semantic-release/exec (npm) 6.0.3
@semantic-release/git (npm) 10.0.1
@semantic-release/github (npm) 8.0.7
@semantic-release/npm (npm) 9.0.2
@testing-library/react (npm) 14.0.0
@testing-library/react-hooks (npm) 6.0.0
@types/lodash.debounce (npm) 4.0.7
@types/lodash.throttle (npm) 4.1.7
@types/react-router-dom (npm) 5.3.3
antd (npm) 5.3.1
babel-loader (npm) ^9.1.2
babel-plugin-istanbul (npm) ^6.1.1
babel-plugin-transform-require-ignore (npm) ^0.1.1
chai (npm) ^4.3.7
css-loader (npm) ^6.7.3
eslint (npm) 8.36.0
eslint-config-standard-with-typescript (npm) 34.0.0
eslint-plugin-import (npm) 2.27.5
eslint-plugin-n (npm) 15.6.1
eslint-plugin-promise (npm) 6.1.1
eslint-plugin-react (npm) 7.32.2
glob (npm) ^9.2.1
husky (npm) ^8.0.3
jsdoc-to-markdown (npm) ^8.0.0
jsdom (npm) ^21.1.1
jsdom-global (npm) ^3.0.2
mocha (npm) 10.2.0
mock-local-storage (npm) 1.1.23
mutation-observer (npm) 1.0.3
nyc (npm) ^15.1.0
react (npm) 18.2.0
react-dom (npm) 18.2.0
react-router-dom (npm) 5.3.4
react-styleguidist (npm) 13.1.1
regenerator-runtime (npm) 0.13.11
rxjs (npm) 7.8.0
semantic-release (npm) ^20.1.1
sinon (npm) ^15.0.2
style-loader (npm) ^3.3.1
ts-loader (npm) 9.4.2
typescript (npm) 5.8.3
url-loader (npm) ^4.1.1
webpack (npm) 5.76.1
Files by Type (count)
JavaScript
88
Markdown
79
TypeScript
74
JSON
7
Other (no ext)
4
YAML
3
Other (.png)
3
Git Ignore
1
Text
1
CSS
1
Shell
1
Files by Type (size)
Other (.png)
593KB
Markdown
274KB
JavaScript
97KB
TypeScript
90KB
JSON
15KB
Git Ignore
4KB
YAML
2KB
Text
1KB
Other (no ext)
345B
CSS
191B
Shell
140B

The LLM identified 4 files worth highlighting for reuse:

A factory function that generates hooks for both localStorage and sessionStorage. It handles SSR gracefully by returning a noop, checks for browser API support, parse JSON safely, and provides a stable setter reference via useCallback. The pattern of creating parameterized hooks from a factory is reusable for other storage-like abstractions (e.g., IndexedDB, cookies). It is self-contained and demonstrates how to build hooks that work consistently across client and server environments.

file: src/factory/createStorageHook.ts ↗ | tags: #factory-pattern #hook-composition #ssr-safe

A tiny utility that wraps console.warn to ensure a message is only displayed once per session. It uses a Map to cache messages and avoid spam in development logs. This pattern is directly reusable in any project that needs to emit non-critical warnings without flooding the console, and it is a clean example of memoization for side effects.

file: src/shared/warnOnce.ts ↗ | tags: #utility #logging #performance

A hook that detects swipe gestures (direction, alpha, count) on a target element or globally. It unifies mouse and touch events, supports configurable direction (horizontal/vertical/both), threshold, and prevents default behavior. The internal state management and comparison logic minimize unnecessary re-renders. This is a sophisticated example of composing multiple low-level event hooks (useMouseEvents, useTouchEvents) into a higher-level gesture abstraction, and it can be extracted for any swipe-based UI.

file: src/useSwipe.ts ↗ | tags: #gesture-detection #event-composition #customizable

A hook that runs a function repeatedly via requestAnimationFrame with progress tracking (startAt, finishAt, increment). It provides an onFinish callback setter. The animation loop is started when the hook mounts and can be stopped by reaching the finishAt value or set to infinite with -1. It gracefully handles SSR by returning a noop. This demonstrates a clean pattern for managing animation frames within React's lifecycle, and the progress callback pattern can be reused for other frame-based animations.

file: src/useRequestAnimationFrame.ts ↗ | tags: #animation-loop #progress-tracking #callback-setter
Last analyzed: 2026-08-30 06:12:35.625536
Next check: 2026-09-29 06:12:35.375562
$ submit: