Hooks

Reusable React hooks exported from @repo/ui for common UI patterns.

Import

import { useKeyboardShortcut, useMediaQuery, useCopyToClipboard } from "@repo/ui";
HookDescription
useClickHandlersProvides onClick and onDoubleClick handlers that don't conflict with each other.
useColumnVisibilityManages column visibility state for table components.
useCookiesRead and write browser cookies with a React-friendly API.
useCopyToClipboardCopy text to clipboard with a copied state that resets after a timeout.
useCurrentAnchorTrack the currently active anchor/hash in the URL for scroll-spy behavior.
useCurrentSubdomainExtract the current subdomain from the browser URL.
useEnterSubmitHandle Enter key to submit forms (with Shift+Enter for newlines).
useInViewportDetect whether an element is visible in the viewport using IntersectionObserver.
useInputFocusedTrack whether any input element on the page currently has focus.
useIntersectionObserverLow-level IntersectionObserver hook for custom viewport detection logic.
useKeyboardShortcutRegister global keyboard shortcuts with modifier key support.
useLocalStoragePersist state to localStorage with automatic JSON serialization.
useMediaQueryReact to CSS media query changes (e.g. responsive breakpoints, dark mode).
useOptimisticUpdateOptimistically update UI state and roll back on error.
usePaginationManage pagination state — current page, page size, total pages.
useRemoveGaParamsAutomatically strip Google Analytics UTM parameters from the URL.
useResizeObserverObserve element size changes via the ResizeObserver API.
useRouterStuffUtilities for reading and updating URL search params with Next.js router.
useScrollTrack the window scroll position for scroll-based UI effects.
useScrollProgressTrack scroll progress as a percentage (0-100) of a container or the page.
useToastWithUndoShow a toast notification with an undo action that reverts the operation.