
Security News
Deno 2.6 + Socket: Supply Chain Defense In Your CLI
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.
react-use
Advanced tools
libreact.
npm i react-use
useBattery β tracks device battery state. useGeolocation β tracks geo location state of user's device. useHover and useHoverDirty β tracks mouse hover state of some element. useHash β tracks location hash value. useIdle β tracks whether user is being inactive.useIntersection β tracks an HTML element's intersection. useKey, useKeyPress, useKeyboardJs, and useKeyPressEvent β track keys. useLocation and useSearchParam β tracks page navigation bar location state.useLongPress β tracks long press gesture of some element.useMedia β tracks state of a CSS media query. useMediaDevices β tracks state of connected hardware devices.useMotion β tracks state of device's motion sensor.useMouse and useMouseHovered β tracks state of mouse position. useMouseWheel β tracks deltaY of scrolled mouse wheel. useNetworkState β tracks the state of browser's network connection. useOrientation β tracks state of device's screen orientation.usePageLeave β triggers when mouse leaves page boundaries.useScratch β tracks mouse click-and-scrub state.useScroll β tracks an HTML element's scroll position. useScrolling β tracks whether HTML element is scrolling.useStartTyping β detects when user starts typing.useWindowScroll β tracks Window scroll position. useWindowSize β tracks Window dimensions. useMeasure and useSize β tracks an HTML element's dimensions. createBreakpoint β tracks innerWidthuseScrollbarWidth β detects browser's native scrollbars width. usePinchZoom β tracks pointer events to detect pinch zoom in and out status. useAudio β plays audio and exposes its controls. useClickAway β triggers callback when user clicks outside target area.useCss β dynamically adjusts CSS.useDrop and useDropArea β tracks file, link and copy-paste drops.useFullscreen β display an element or video full-screen. useSlider β provides slide behavior over any HTML element. useSpeech β synthesizes speech from a text string. useVibrate β provide physical feedback using the Vibration API. useVideo β plays video, tracks its state, and exposes playback controls. useRaf β re-renders component on each requestAnimationFrame.useInterval and useHarmonicIntervalFn β re-renders component on a set interval using setInterval.useSpring β interpolates number over time according to spring dynamics.useTimeout β re-renders component after a timeout.useTimeoutFn β calls given function after a timeout. useTween β re-renders component, while tweening a number from 0 to 1. useUpdate β returns a callback, which re-renders component when called.
useAsync, useAsyncFn, and useAsyncRetry β resolves an async function.useBeforeUnload β shows browser alert when user try to reload or close the page.useCookie β provides way to read, update and delete a cookie. useCopyToClipboard β copies text to clipboard.useDebounce β debounces a function. useError β error dispatcher. useFavicon β sets favicon of the page.useLocalStorage β manages a value in localStorage.useLockBodyScroll β lock scrolling of the body element.useRafLoop β calls given function inside the RAF loop.useSessionStorage β manages a value in sessionStorage.useThrottle and useThrottleFn β throttles a function. useTitle β sets title of the page.usePermission β query permission status for browser APIs.
useEffectOnce β a modified useEffect hook that only runs once.useEvent β subscribe to events.useLifecycles β calls mount and unmount callbacks.useMountedState and useUnmountPromise β track if component is mounted.usePromise β resolves promise only while component is mounted.useLogger β logs in console as component goes through life-cycles.useMount β calls mount callbacks.useUnmount β calls unmount callbacks.useUpdateEffect β run an effect only on updates.useIsomorphicLayoutEffect β useLayoutEffect that that works on server.useDeepCompareEffect, useShallowCompareEffect, and useCustomCompareEffect
createMemo β factory of memoized hooks.createReducer β factory of reducer hooks with custom middleware.createReducerContext and createStateContext β factory of hooks for a sharing state between components.useDefault β returns the default value when state is null or undefined.useGetSet β returns state getter get() instead of raw state.useGetSetState β as if useGetSet and useSetState had a baby.useLatest β returns the latest state or propsusePrevious β returns the previous state or props. usePreviousDistinct β like usePrevious but with a predicate to determine if previous should update.useObservable β tracks latest value of an Observable.useRafState β creates setState method which only updates after requestAnimationFrame. useSetState β creates setState method which works like this.setState. useStateList β circularly iterates over an array. useToggle and useBoolean β tracks state of a boolean. useCounter and useNumber β tracks state of a number. useList useUpsertuseMap β tracks state of an object. useSet β tracks state of a Set. useQueue β implements simple queue.useStateValidator β tracks state of an object. useStateWithHistory β stores previous state values and provides handles to travel through them. useMultiStateValidator β alike the useStateValidator, but tracks multiple states at a time. useMediatedState β like the regular useState but with mediation by custom function. useFirstMountState β check if current render is first. useRendersCount β count component renders. createGlobalState β cross component shared state.useMethods β neat alternative to useReducer. useEnsuredForwardedRef and ensuredForwardRef β use a React.forwardedRef safely.
Usage β how to import.
Unlicense β public domain.
Support β add yourself to backer list below.
Recompose is a React utility belt for function components and higher-order components. It's similar to react-use in that it provides a set of helpers for creating and manipulating components, but it does not focus exclusively on hooks.
React-powerhooks offers a set of hooks that can be used to manage state and lifecycle in React components, similar to react-use. However, react-use has a broader range of hooks, including those for sensors and UI state management.
FAQs
Collection of React Hooks
The npm package react-use receives a total of 2,500,949 weekly downloads. As such, react-use popularity was classified as popular.
We found that react-use demonstrated a not healthy version release cadence and project activity because the last version was released a year ago.Β It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.

Security News
New DoS and source code exposure bugs in React Server Components and Next.js: whatβs affected and how to update safely.

Security News
Socket CEO Feross Aboukhadijeh joins Software Engineering Daily to discuss modern software supply chain attacks and rising AI-driven security risks.