Newsletter
Join the Community
Subscribe to our newsletter for the latest news and updates
React hook library, ready to use, written in Typescript.
usehooks-ts is an open-source React hook library written in TypeScript that gives developers a set of ready-to-use hooks for common state management and browser API tasks. It is created by Julien Caron and maintained by a team of over 250 contributors, and is distributed as an npm package under the MIT License.
usehooks-ts is a React hook library written in TypeScript, installable via npm with npm i usehooks-ts. It provides a collection of hooks covering state management (such as useBoolean, useCounter, useToggle), browser APIs (such as useLocalStorage, useSessionStorage, useMediaQuery, useDarkMode), and DOM utilities (such as useHover, useIntersectionObserver, useOnClickOutside). The library follows the DRY (Don't Repeat Yourself) principle so developers can reuse well-tested logic instead of writing it from scratch.
The library is designed to be minimal and fully tree-shakable when using the ESM version, meaning only the hooks you actually import are included in your final bundle. This keeps the performance cost of adding the library negligible, which is especially important for production React applications.
useBoolean, useCounter, useMap, useStep), storage (useLocalStorage, useSessionStorage, useReadLocalStorage), DOM events (useEventListener, useClickAnyWhere, useHover), timers (useInterval, useTimeout, useCountdown), and more.useMediaQuery (Match Media API), useCopyToClipboard (Clipboard API), useIntersectionObserver (Intersection Observer API), and useResizeObserver (ResizeObserver API) abstract complex browser features into simple React hooks.useIsomorphicLayoutEffect automatically selects between useLayoutEffect and useEffect depending on the environment, while useIsClient and useIsMounted help avoid hydration mismatches.useDarkMode returns the current dark mode state, and useTernaryDarkMode supports system/dark/light modes with localStorage persistence.useLocalStorage or useSessionStorage to save a value across page reloads, reading it back with useReadLocalStorage if you only need the value.useWindowSize reports window dimensions, useMediaQuery listens to a CSS media query string, and useIntersectionObserver observes when an element enters the viewport.useDarkMode manages the current theme, and useTernaryDarkMode extends it to support system, dark, and light preferences with persistent storage.useDebounceCallback creates a debounced callback, useInterval and useTimeout wrap the corresponding timer APIs, and useEventListener attaches listeners to DOM elements or the window.Yes, usehooks-ts is open-source and released under the MIT License, so you can use it in commercial and personal projects without licensing fees.
Run npm i usehooks-ts in your project. The package is available on npm and includes both CommonJS and ESM builds.
The library includes hooks that respect the rendering environment. useIsomorphicLayoutEffect picks the correct effect implementation, and useIsClient lets you defer client-only logic until hydration is complete.
It includes more than 30 hooks, such as useBoolean, useCounter, useDarkMode, useDebounceCallback, useLocalStorage, useSessionStorage, useMediaQuery, useWindowSize, useCopyToClipboard, and useIntersectionObserver. The full list is available on the project's documentation site, usehooks-ts.com.
The README does not mention React Native support; the library targets web APIs like window, document, localStorage, and matchMedia, so it is primarily designed for web React applications.
