Hooks
36 React hooks for UI state, DOM interactions, events, timing, theming, accessibility, and SSR.
A collection of 36 React hooks covering UI state management, persistence, DOM interactions, event handling, timing, theming, accessibility, and SSR.
What's new in 2.9 — useMediaQuery, useBreakpoint and useLocalStorage (and therefore useColorScheme / useReducedMotion) are now hydration-safe. They are built on useSyncExternalStore with a server snapshot (false, the smallest breakpoint, and initialValue respectively): the server and the hydrating client render that value, then React re-renders with the real one right after hydration. Client-only renders still get the real value on the first render. Also: useBreakpoint shares one rAF-throttled resize listener across all instances, useLocalStorage keeps same-key instances in sync within the tab, useFocusTrap no longer lets focus escape, and useEventListener no longer re-attaches when options is an inline object.
React Native — the native entry point exports 21 of the 36 hooks. DOM-only hooks (useClickOutside, useCopyToClipboard, useElementSize, useEventListener, useFocusTrap, useIntersection, useLocalStorage, useMediaQuery, useOnlineStatus, usePageVisibility, useResizeObserver, useScrollLock, useWindowScroll) and the web-only useFocus / useHover are not available there. useBreakpoint, useColorScheme, useReducedMotion and useWindowResize use RN APIs (Dimensions, Appearance, AccessibilityInfo); useKeyboard is a no-op.
Installation
npm install @vitus-labs/hooksTry It Live
Hook Categories
State Management
| Hook | Description |
|---|---|
useControllableState | Unified controlled/uncontrolled pattern |
useToggle | Boolean toggle with convenience methods |
usePrevious | Previous render value |
useLatest | Always-current value ref |
useLocalStorage | State synced with localStorage (hydration-safe, cross-tab) |
DOM & Measurement
| Hook | Description |
|---|---|
useElementSize | Track element dimensions via ResizeObserver |
useResizeObserver | Full contentRect of a ref'd element |
useIntersection | Observe element visibility |
useClickOutside | Detect clicks outside an element |
useMergedRef | Combine multiple refs into one |
useScrollLock | Lock page scroll |
useWindowResize | Track viewport dimensions |
useWindowScroll | Track window scroll position |
Events & Interaction
| Hook | Description |
|---|---|
useHover | Mouse hover state |
useFocus | Focus/blur state |
useFocusTrap | Trap keyboard focus in container |
useKeyboard | Listen for key presses |
useEventListener | Typed DOM event subscription with cleanup |
useCopyToClipboard | Copy text with a transient "copied" flag |
Timing
| Hook | Description |
|---|---|
useDebouncedCallback | Debounce function calls |
useDebouncedValue | Debounce a value |
useThrottledCallback | Throttle function calls |
useInterval | Declarative setInterval |
useTimeout | Declarative setTimeout |
Theme & Responsive
| Hook | Description |
|---|---|
useBreakpoint | Active breakpoint name |
useMediaQuery | CSS media query matching |
useThemeValue | Deep-read theme values |
useRootSize | Root font size + px/rem conversion |
useSpacing | Spacing scale function |
Accessibility, SSR & Environment
| Hook | Description |
|---|---|
useColorScheme | OS color scheme preference |
useReducedMotion | Motion preference |
useIsClient | false on server / first render, true after mount |
usePageVisibility | Whether the tab is visible |
useOnlineStatus | Whether the browser is online |
useIsomorphicLayoutEffect | SSR-safe layout effect |
useUpdateEffect | Skip-initial-mount effect |
Last updated on