usehooks

A collection of modern, server-safe React hooks for browser APIs, storage, and UI interaction patterns from the ui.dev team.

Library
npm
v2.4.1
11,503stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
46/100Fair
Development Activity0
Maintenance20
Community64
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
50/100Fair
Architecture68
Code Quality35
Innovation62
Learning Curve35

usehooks (published as @uidotdev/usehooks) is a single-file, dependency-free collection of roughly three dozen React hooks covering the browser-API and UI-state problems most apps eventually reimplement themselves: battery status, geolocation, network state, clipboard access, local/session storage, intersection and resize observers, media queries, mouse/hover tracking, debouncing/throttling, and simple undo/redo history state.

Each hook is exported individually from one ESM entry point with no build step and no runtime dependencies beyond React itself (peer dependency on React 18+). Several of the browser-state hooks (useMediaQuery, useLocalStorage, useSessionStorage, useNetworkState, usePreferredLanguage, useVisibilityChange) are built on React’s useSyncExternalStore, making them safe under concurrent rendering rather than relying on ad hoc effect-driven state that can tear during concurrent updates. The project also publishes an experimental channel (@uidotdev/usehooks@experimental) with additional hooks like useFetch, useKeyPress, and useInterval that haven’t been promoted to the stable release.

What You Get

  • ~37 standalone hooks covering storage (useLocalStorage, useSessionStorage), device/browser state (useBattery, useGeolocation, useNetworkState, useOrientation, usePreferredLanguage), and observers (useIntersectionObserver, useMeasure)
  • Concurrent-safe implementations of the storage and media-query hooks built on React’s useSyncExternalStore, avoiding the tearing bugs older effect-based equivalents can hit
  • Interaction hooks for common UI patterns: useClickAway, useHover, useLongPress, useMouse, useDebounce, useThrottle, useToggle
  • State-container hooks that go beyond useState: useHistoryState (undo/redo), useMap, useSet, useQueue, useList, useObjectState
  • Hand-written TypeScript declarations (index.d.ts) shipped alongside the ESM source, with no build/bundling step required to consume the package
  • An experimental release channel (@uidotdev/usehooks@experimental) previewing additional hooks such as useFetch, useInterval, useKeyPress, and useEventListener before they’re promoted to stable

Common Use Cases

  • Persisting UI state (theme, form drafts, filters) to localStorage/sessionStorage with automatic cross-tab sync via useLocalStorage/useSessionStorage
  • Reacting to connectivity and device conditions (battery level, network type, online/offline) to adapt UI behavior on constrained devices
  • Building interaction affordances like click-away dismissal, long-press, hover tracking, and lazy-load triggers via useIntersectionObserver
  • Debouncing or throttling rapidly changing values (search input, scroll position, resize events) without hand-rolling timers in every component
  • Adding undo/redo to editors or wizards with useHistoryState instead of building a custom reducer for history tracking

Under The Hood

Architecture The entire package is a single flat ESM file (index.js, ~1,370 lines) exporting roughly three dozen independent hook functions plus a handful of private, module-scoped helpers (isShallowEqual, throttle, dispatchStorageEvent, isPlainObject, isTouchEvent/isMouseEvent) shared by a few related hooks (useIdle reuses throttle, useLongPress reuses the event-type checks, the storage hooks share dispatchStorageEvent). There’s no shared runtime object graph or internal module boundary to reason about — each hook is self-contained and composed directly from React’s own primitives (useState, useEffect, useLayoutEffect, useSyncExternalStore, useReducer, useRef, useMemo, useCallback), so removing or changing one hook cannot break another; the only coupling risk is within the small set of shared private helpers.

Tech Stack The package has no runtime dependencies and a single peer dependency on react/react-dom >=18.0.0 (pinned to ^18.2.0 in devDependencies alongside @types/react ^18.2.20 and typescript ^5.1.6). It ships zero build output — package.json’s “exports” field points directly at the hand-authored index.js (ESM, “type”: “module”), and index.d.ts is a hand-written declaration file checked locally against a strict tsconfig.json (ESNext target/module, strict mode, allowJs) rather than emitted by a compiler step. The repository also contains a separate usehooks.com/ subdirectory — an Astro-based documentation site with a live demo per hook — that is entirely decoupled from the published npm package.

Code Quality No test files exist anywhere in the package source, and the repository has no CI configuration (no .github/workflows) to run type-checks, lint, or tests on push. Naming is consistent (useXxx hooks, camelCase helpers) and effect cleanup is handled correctly throughout (every addEventListener/observer pairs with a matching removal in the effect’s return function), but there is no automated way to verify the hand-written index.d.ts stays in sync with index.js, and no linter or formatter configuration is present at the package root. Error handling is inconsistent across hooks: useCounter and useWindowScroll throw explicit errors on invalid input, while useLocalStorage/useSessionStorage swallow JSON-parse failures behind a bare console.warn.

API Design The library’s core ergonomic choice is exposing several browser-state hooks (useLocalStorage, useSessionStorage, useMediaQuery, useNetworkState, usePreferredLanguage, useVisibilityChange) through useSyncExternalStore rather than the effect-plus-state pattern common in older hook collections, making them correctly tearing-safe under React 18’s concurrent renderer — a real correctness advantage over collections written before that API existed. Every hook is zero-config and independently importable with no provider or setup step, keeping the surface area small and predictable, though several hooks (useBattery, useGeolocation) are thin wrappers around their underlying Web APIs with limited abstraction beyond removing effect boilerplate, and SSR safety is handled ad hoc — some hooks simply throw (“useMediaQuery is a client-only hook”) when their server snapshot is invoked, leaving guard logic to the consumer.

Used by 14 apps in this directory

TypeScript
53%
MIT

Anarlog

Note Taking · AI Assistants · Productivity

9,252

Anarlog is an open-source, local-first AI meeting notetaker that records, transcribes, and summarizes meetings entirely on your device — no cloud lock-in, no mandatory account, and every note saved as a plain markdown file you own forever.

View details
86
Repo Health
77
Technical
68
Dependency
Built with
TypeScript53%
Rust35%
Updated today
Java
73%
Other

ByteChef

Automation · AI Agents

1,000

Unified open-source platform for AI agent orchestration and workflow automation with 180+ connectors, MCP support, and durable execution.

View details
85
Repo Health
82
Technical
70
Dependency
Built with
Java73%
TypeScript26%
Updated yesterday
Rust
53%
Other

Cap

Team Chat · Video Conferencing

21,859

Open source Loom alternative with GPU-accelerated recording, instant share links, AI summaries, and full self-hosting via Docker Compose.

View details
89
Repo Health
81
Technical
64
Dependency
Built with
Rust53%
TypeScript43%
Updated yesterday
Rust
67%
Other

DefGuard

Security · Networking · Authentication

2,819

Self-hosted secure remote access that unifies WireGuard VPN, identity management, and connection-level MFA in one open-source platform.

View details
84
Repo Health
82
Technical
72
Dependency
Built with
Rust67%
TypeScript31%
Updated 3 days ago
TypeScript
99%
AGPL 3.0

fountain-ink

Blogging

64

A self-hostable, decentralized blogging platform built on Lens Protocol — own your content, audience, and distribution forever.

View details
26
Repo Health
66
Technical
66
Dependency
Built with
TypeScript99%
Updated 7 months ago
TypeScript
99%
AGPL 3.0

Karakeep

Bookmarks Archiving

28,871

Self-hosted bookmark manager that captures links, notes, images, and PDFs with AI tagging, full-text search, and automatic archiving.

View details
88
Repo Health
76
Technical
66
Dependency
Built with
TypeScript99%
Updated 1 weeks ago
Python
61%
Apache 2.0

marimo

Developer Tools · Data Engineering

22,670

A reactive Python notebook that eliminates hidden state, runs reproducibly, and deploys as a web app or script — stored as pure Python, built for the AI era.

View details
90
Repo Health
91
Technical
65
Dependency
Built with
Python61%
TypeScript37%
Updated yesterday
TypeScript
86%
MIT

medusa

Ecommerce

36,163

The most flexible open-source commerce platform — build B2C, B2B, and marketplace applications with modular, composable commerce primitives.

View details
93
Repo Health
87
Technical
63
Dependency
Built with
TypeScript86%
JavaScript14%
Updated 2 days ago
TypeScript
97%
Other

nango

Developer Tools · Automation · Authentication

11,746

Build product integrations with AI using 800+ APIs — auth, proxy, and TypeScript functions on production-grade infrastructure.

View details
93
Repo Health
85
Technical
68
Dependency
Built with
TypeScript97%
Updated 3 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search