npm i usehooks-ts
useHooks(π₯).ts is a React hooks library, written in Typescript and easy to use. It provides a set of hooks that enables you to build your React applications faster. The hooks are built upon the principles of DRY (Don't Repeat Yourself). There are hooks for most common use cases you might need.
The library is designed to be as minimal as possible. It is fully tree-shakable (using the ESM version), meaning that you only import the hooks you need, and the rest will be removed from your bundle making the cost of using this library negligible. Most hooks are extensively tested and are being used in production environments.
import { useLocalStorage } from 'usehooks-ts'
function Component() {
const [value, setValue] = useLocalStorage('my-localStorage-key', 0)
// ...
}
useBoolean
β handles boolean state with useful utility functions.useClickAnyWhere
β handles click events anywhere on the document.useCopyToClipboard
β copies text to the clipboard.useCountdown
β manages countdown.useCounter
β manages a counter with increment, decrement, reset, and setCount functionalities.useDarkMode
β returns the current state of the dark mode.useDebounceCallback
β creates a debounced version of a callback function.useDebounceValue
β returns a debounced version of the provided value, along with a function to update it.useDocumentTitle
β sets the document title.useEventCallback
β creates a memoized event callback.useEventListener
β attaches event listeners to DOM elements, the window, or media query lists.useHover
β tracks whether a DOM element is being hovered over.useIntersectionObserver
β tracks the intersection of a DOM element with its containing element or the viewport.useInterval
β creates an interval that invokes a callback function at a specified delay.useIsClient
β determines if the code is running on the client side (in the browser).useIsMounted
β determines if the component is currently mounted.useIsomorphicLayoutEffect
β uses eitheruseLocalStorage
β uses local storage to persist state across page reloads.useMap
β manages a key-value map state with setter actions.useMediaQuery
β tracks the state of a media query.useOnClickOutside
β handles clicks outside a specified element.useReadLocalStorage
β reads a value from local storage, closely related to useLocalStorage().useResizeObserver
β observes the size of an element using the ResizeObserver API.useScreen
β tracks the screen dimensions and properties.useScript
β dynamically loads scripts and tracking their loading status.useScrollLock
β A custom hook that locks and unlocks scroll.useSessionStorage
β uses session storage to persist state across page reloads.useStep
β manages and navigates between steps in a multi-step process.useTernaryDarkMode
β manages ternary (system, dark, light) dark mode with local storage support.useTimeout
β handles timeouts in React components.useToggle
β manages a boolean toggle state in React components.useUnmount
β runs a cleanup function when the component is unmounted.useWindowSize
β tracks the size of the window.
Big thanks go to all our backers! [Become a backer]
Sentry |
KATT |
Adhi Ravishankar |
great-work-told-is |
Big thanks go to all our contributors! [Become a contributor]
This project follows the all-contributors specification (emoji key). Contributions of any kind welcome!
This project is MIT licensed.