Getting started
70+ small, typed React hooks for React and Next.js apps. A TypeScript hooks library for
state, localStorage, URL query params, debounce and throttle, timers, click outside,
keyboard shortcuts, media queries, element size, browser APIs and more. Every hook is
SSR-safe, so it works in the Next.js App Router and Pages Router, Remix and any other
server-rendered React app, as well as in single-page apps built with Vite.
- SSR-safe and Next.js ready. No hook touches
windowordocumentwhile rendering on the server, and each one documents the value it returns there. See Using with Next.js. - TypeScript first. Written in strict TypeScript with precise types, such as checked
query param keys and typed DOM events. No
@typespackage needed. - Tiny and tree-shakeable. Zero dependencies:
reactis the only peer dependency. All the hooks together are about 12 kB minified and gzipped, and your bundle only includes the ones you import. A test bundles each hook alone to keep it that way. - No
useCallbackneeded. Pass inline functions: hooks always call your latest callback without re-subscribing. - Tested in real browsers. Unit tests in jsdom, and end-to-end tests in Chromium, Firefox and WebKit.
- React 18 and 19. Ships ESM and CommonJS builds.
Installation
npm install react-honey-hooks
pnpm add react-honey-hooks
yarn add react-honey-hooks
Requires React 18 or newer.
Quick start
Import the hooks you need by name:
import { useState } from "react";
import { useDebouncedValue, useLocalStorage, useMediaQuery } from "react-honey-hooks";
function Search() {
const [query, setQuery] = useState("");
const debouncedQuery = useDebouncedValue(query, 300); // fetch with this one
const [theme, setTheme] = useLocalStorage<"light" | "dark">("theme", "light");
const isMobile = useMediaQuery("(max-width: 640px)");
return (
<div data-theme={theme}>
<input value={query} onChange={(event) => setQuery(event.target.value)} />
<button onClick={() => setTheme(theme === "light" ? "dark" : "light")}>Toggle theme</button>
{!isMobile && <p>Searching for “{debouncedQuery}”</p>}
</div>
);
}