Website review
This review may include AI-generated content and is not individually verified. Domain, certificate and other facts come from the observed data on this page.
What is useHooks?
useHooks is a library of ready-made React hooks maintained by the ui.dev team. Rather than documenting one hook, it collects dozens of reusable hooks in a single package, installable as @uidotdev/usehooks. The site itself serves as both the library's documentation and a browsable catalog: each hook gets its own page with usage details, and the collection is listed alphabetically or sorted by popularity.
What kinds of hooks it covers
The catalog spans several everyday React problems:
- State and storage:
useLocalStorage,useSessionStorage,useHistoryState,useMap,useSet,useList,useQueue,useToggle,useCounter,useDefault - Browser and device APIs:
useBattery,useGeolocation,useNetworkState,useOrientation,usePreferredLanguage,useWindowSize,useWindowScroll,useMediaQuery,useCopyToClipboard,useFavicon,useDocumentTitle - Events and interaction:
useClickAway,useLongPress,useKeyPress,useHover,useMouse,useEventListener,usePageLeave,useVisibilityChange,useIdle - Timing:
useDebounce,useThrottle,useInterval,useIntervalWhen,useTimeout,useCountdown,useRandomInterval,useContinuousRetry - Rendering and measurement:
useIntersectionObserver,useMeasure,usePrevious,useRenderCount,useRenderInfo,useIsFirstRender,useIsClient,useScript,useFetch
Who it is for
It suits React developers who would otherwise rewrite the same small hooks across projects, and teams that want one consistent, tested dependency instead of scattered snippets. Beginners benefit from reading the implementations as learning material — the site explicitly frames the hooks as things you can learn to build yourself. Developers working with server rendering should note the "server-safe" framing in the site's own description, which suggests the hooks are written with SSR in mind.
Trade-offs to weigh
Pulling in a whole hooks package means you depend on someone else's API choices and update cadence; if you only need useDebounce, a few lines of your own code may be simpler than a dependency. The counter-argument is consistency and correctness across many hooks. The site also mentions subscribing, implying some content or offering sits behind an email signup — worth checking before you rely on it.
A practical next step
Pick the single hook closest to a problem you have right now — say, persisting a theme choice with useLocalStorage — read its page, then decide whether to install the package or copy the pattern. If you want a broader React learning path, the same team publishes material at ui.dev.
How do I install and use a hook from the useHooks library?
Install the package once, then import only the hooks you need in each component.
npm i @uidotdev/usehooks
import { useDebounce, useLocalStorage } from "@uidotdev/usehooks";
function SearchBox() {
const [query, setQuery] = useState("");
const debouncedQuery = useDebounce(query, 300);
useEffect(() => {
// runs 300ms after the user stops typing
fetchResults(debouncedQuery);
}, [debouncedQuery]);
return <input value={query} onChange={(e) => setQuery(e.target.value)} />;
}
The library ships as a single package covering the hooks listed on useHooks, so there is no per-hook install step. Named imports keep your bundle from pulling in hooks you never call, provided your bundler tree-shakes.
Picking the right hook for a job
| Goal | Hook from the library | Practical note |
|---|---|---|
| Delay a value or callback | useDebounce |
Common for search inputs and resize handlers |
| Persist state across reloads | useLocalStorage |
Tied to one browser; not a server-side store |
| Read viewport width | useWindowSize |
Useful for responsive logic JS can't express in CSS |
| Detect element visibility | useIntersectionObserver |
Good for lazy loading and scroll-triggered UI |
| Track online/offline status | useNetworkState |
Pair with a retry or offline message |
| Compare current and prior value | usePrevious |
Handy for animations and change detection |
A concrete first step
If you are new to the library, start with useLocalStorage: replace one useState call in an existing component, reload the page, and confirm the value survives. That gives you a feel for the import pattern and the API shape before you adopt hooks that touch browser APIs like geolocation or the clipboard.
Two things to watch. First, hooks that read browser-only APIs (useWindowSize, useGeolocation, useNetworkState) behave differently during server rendering; the library markets its hooks as server-safe, but you should still verify each one in your own SSR or framework setup. Second, the source page mentions a subscribe option, so check the site directly if you want updates or additional material rather than assuming everything is bundled into the npm package.
Which useHooks hook should I choose for debouncing an input or event handler?
Use useDebounce from useHooks. It delays a state update until input has settled, which is the usual way to keep a search field or resize handler from firing on every keystroke or pixel change.
The page lists useDebounce among the library's hooks with the description "Delay the execution of function or state update with useDebounce." That phrasing matters: it is built around delaying a value or state update, not wrapping an arbitrary callback. If you need to debounce a plain function rather than a value, you would typically debounce the state that drives it, or reach for a general-purpose debounce utility.
A concrete pattern: keep the raw input in state, pass it through useDebounce with a short delay, then run your fetch or filter against the debounced value. The input stays responsive while the expensive work waits.
Practical checks before adopting it:
- Install from the package shown on the page (
@uidotdev/usehooks) so you get the maintained version. - Confirm the hook's delay argument and return shape in its individual page, since those details drive how you wire it up.
- For throttling instead of waiting for a pause,
useThrottleis the sibling hook to consider. - The library is described as server-safe, so it should not break during server rendering, but browser-only hooks still need client-side execution.
Next step: open the useDebounce page at useHooks and copy the example, then adjust the delay to your input's tolerance.
How can I persist React state to localStorage or sessionStorage with useHooks?
Use two hooks from the library: useLocalStorage for data that should survive a browser restart and useSessionStorage for data that should clear when the tab closes. Both mirror the useState API, so persistence is mostly a drop-in replacement for state you already have.
useHooks lists both hooks, described as storing, retrieving and synchronizing data from the browser's localStorage and sessionStorage APIs respectively.
Choosing between them
| Hook | Survives tab close | Survives browser restart | Shared across tabs |
|---|---|---|---|
useLocalStorage |
Yes | Yes | Yes, same origin |
useSessionStorage |
No | No | No, per tab |
Pick useLocalStorage for preferences, theme, a draft, a saved filter set, or a shopping cart. Pick useSessionStorage for a multi-step form in progress, a one-time dismissal notice, or a temporary token you do not want lingering.
A concrete scenario
You are building a settings panel with a dark-mode toggle and a "compact table" switch. A user sets both, closes the laptop and returns tomorrow. With useLocalStorage, the values rehydrate on load and the UI matches what they left. If instead you were halfway through a three-step signup form, useSessionStorage keeps their input while the tab is open but starts clean next time — which is usually what people expect from a form.
Practical caveats
- Server rendering. The page markets these hooks as server-safe, but browser storage does not exist on the server. Expect the first client render to reconcile with stored values; the library also exposes
useIsClientanduseIsFirstRenderif you need to gate rendering. - Storage is synchronous and string-based. Large objects written on every keystroke will cost you. Pair with
useDebouncewhen persisting input as the user types. - Cross-tab sync.
localStoragechanges fire storage events in other tabs; the hook's "synchronize" wording suggests it listens for them. Verify against your own browser matrix if cross-tab consistency matters. - Quota and privacy mode. Storage can throw when full or blocked. Wrap risky writes and degrade to in-memory state.
Next step
Install the package, swap one useState call for useLocalStorage, and confirm the value survives a hard refresh before converting anything else. Read the individual hook pages on useHooks for the exact signature and return shape.
How do I track browser window size or network status with useHooks?
For window size, use useWindowSize; for network status, use useNetworkState. Both come from the @uidotdev/usehooks package, so install it once and import the hook you need.
import { useWindowSize, useNetworkState } from "@uidotdev/usehooks";
function StatusBar() {
const { width, height } = useWindowSize();
const { online, downlink, effectiveType } = useNetworkState();
return (
<p>
{width}×{height} · {online ? "online" : "offline"}
{effectiveType ? ` (${effectiveType})` : ""}
</p>
);
}
useWindowSize subscribes to resize events and gives you current dimensions, which suits responsive layouts, canvas sizing, or conditional rendering that CSS media queries can't express. useNetworkState exposes the browser's Network Information API, so treat it as a hint: online is reliable enough for showing an offline banner, but downlink and effectiveType vary by browser and shouldn't drive critical logic.
A practical decision rule: if you only need to change styles, prefer CSS media queries; reach for useWindowSize when JavaScript needs the number (measuring a chart, positioning a tooltip). For network status, combine useNetworkState with a failed-fetch fallback, since a reported "online" state doesn't guarantee a working request.
If you'd rather write these hooks yourself to understand the pattern, the site's own tutorials walk through building them, and the full list sits alongside related hooks like useMediaQuery and useOrientation at useHooks.
How can I learn to build these React hooks myself?
The site answers this directly: its own tagline says "Master React by learning how to build useHooks yourself," and each hook page is written to show the implementation, not just the API. So the intended path is to treat the library as a set of worked examples rather than a black box.
A practical way to work through it
Pick hooks that match problems you already have, and rebuild each one from scratch before reading the source:
- Start with state and timing hooks —
useDebounce,usePrevious,useToggle,useTimeout. These are short, and they teach you refs, cleanup, and dependency arrays. - Move to browser-API hooks —
useLocalStorage,useWindowSize,useMediaQuery,useIntersectionObserver. Here the real lesson is subscribing and unsubscribing correctly, plus handling server rendering. - Then tackle data and async hooks —
useFetch,useContinuousRetry,useNetworkState— where you deal with race conditions, aborting requests, and retries. - Finish with composition hooks like
useList,useMap,useQueue,useSet, which show how to wrap complex state in a hook-shaped API.
For each one, write your version first, then compare against the site's implementation and note where yours differs: missing cleanup, stale closures, unnecessary re-renders, or no SSR guard.
What to pay attention to while rebuilding
- Cleanup: every listener, interval, or observer should be removed on unmount and when inputs change.
- SSR safety: the library advertises its hooks as server-safe, so watch for
window/documentaccess guarded behind a client check such asuseIsClient. - Refs vs. state: many hooks keep values in refs to avoid re-renders — a pattern worth copying deliberately.
- Stable callbacks:
useCallback/useRefusage is what keeps these hooks from causing render loops in consumers.
Where to go next
Build one small feature using only hooks you wrote yourself — for example, a search box that debounces input, persists recent queries to storage, and shows a retry button when offline. That forces you to combine useDebounce, useLocalStorage, and useNetworkState and exposes the gaps in your implementations.
If you want a broader React reference alongside it, the official docs at React cover the underlying rules these hooks depend on, and MDN Web Docs is useful for the browser APIs behind hooks like useIntersectionObserver and useGeolocation.
User reviews (0)