--- name: react-use-hooks description: Apply react-use hooks where appropriate to build concise, maintainable React features. license: Unlicense metadata: author: Adapted from streamich/react-use version: "1.0" compatibility: Requires React 16.8+ with hooks support --- # React-Use Hooks This skill is a decision-and-implementation guide for react-use hooks in React projects. It maps requirements to the most suitable react-use hook, applies the correct usage pattern, and prefers hook-based solutions over bespoke code to keep implementations concise, maintainable, and performant. ## When to Apply - Apply this skill whenever assisting user development work in React. - Always check first whether a react-use hook can implement the requirement. - Prefer react-use hooks over custom code to improve readability, maintainability, and performance. - Map requirements to the most appropriate hook and follow the hook's invocation rule. - Please refer to the `Invocation` field in the below hooks table. For example: - `AUTO`: Use automatically when applicable. - `EXTERNAL`: Use only if the user already installed the required external dependency; otherwise reconsider, and ask to install only if truly needed. - `EXPLICIT_ONLY`: Use only when explicitly requested by the user. > *NOTE* User instructions in the prompt or `AGENTS.md` may override a hook's default `Invocation` rule. ## Hooks All hooks listed below are part of the [react-use](https://github.com/streamich/react-use) library, each section categorizes hooks based on their functionality. IMPORTANT: Each hook entry includes a short `Description` and a detailed `Reference`. When using any hook, always consult the corresponding document in `./references` for Usage details and Type Declarations. ### Sensors | Hook | Description | Invocation | |------|-------------|------------| | [`createBreakpoint`](./references/createBreakpoint.md) | laptopL: 1440, laptop: 1024, tablet: 768 | AUTO | | [`useBattery`](./references/useBattery.md) | React sensor hook that tracks battery status. | AUTO | | [`useGeolocation`](./references/useGeolocation.md) | React sensor hook that tracks user's geographic location. This hook accepts [position options](https | AUTO | | [`useHash`](./references/useHash.md) | React sensor hook that tracks browser's location hash. | AUTO | | [`useHover`](./references/useHover.md) | React UI sensor hooks that track if some element is being hovered | AUTO | | [`useHoverDirty`](./references/useHoverDirty.md) | Tracks mouse hover state using a ref (more direct than useHover). | AUTO | | [`useIdle`](./references/useIdle.md) | React sensor hook that tracks if user on the page is idle. | AUTO | | [`useIntersection`](./references/useIntersection.md) | React sensor hook that tracks the changes in the intersection of a target element with an ancestor e | AUTO | | [`useKey`](./references/useKey.md) | React UI sensor hook that executes a `handler` when a keyboard key is used. | AUTO | | [`useKeyboardJs`](./references/useKeyboardJs.md) | React UI sensor hook that detects complex key combos like detecting when | EXTERNAL | | [`useKeyPress`](./references/useKeyPress.md) | React UI sensor hook that detects when the user is pressing a specific | AUTO | | [`useKeyPressEvent`](./references/useKeyPressEvent.md) | This hook fires `keydown` and `keyup` callbacks, similar to how [`useKey`](./useKey.md) | AUTO | | [`useLocation`](./references/useLocation.md) | React sensor hook that tracks brower's location. | AUTO | | [`useLongPress`](./references/useLongPress.md) | React sensor hook that fires a callback after long pressing. | AUTO | | [`useMeasure`](./references/useMeasure.md) | React sensor hook that tracks dimensions of an HTML element using the [Resize Observer API](https:// | AUTO | | [`useMedia`](./references/useMedia.md) | React sensor hook that tracks state of a CSS media query. | AUTO | | [`useMediaDevices`](./references/useMediaDevices.md) | React sensor hook that tracks connected hardware devices. | AUTO | | [`useMotion`](./references/useMotion.md) | React sensor hook that uses device's acceleration sensor to track its motions. | AUTO | | [`useMouse`](./references/useMouse.md) | React sensor hooks that re-render on mouse position changes. `useMouse` simply tracks | AUTO | | [`useMouseHovered`](./references/useMouseHovered.md) | Extended mouse tracking with options for bounded coordinates and hover-only tracking. | AUTO | | [`useMouseWheel`](./references/useMouseWheel.md) | React Hook to get deltaY of mouse scrolled in window. | AUTO | | [`useNetworkState`](./references/useNetworkState.md) | Tracks the state of browser's network connection. | AUTO | | [`useOrientation`](./references/useOrientation.md) | React sensor hook that tracks screen orientation of user's device. | AUTO | | [`usePageLeave`](./references/usePageLeave.md) | React sensor hook that fires a callback when mouse leaves the page. | AUTO | | [`usePinchZoom`](./references/usePinchZoom.md) | React sensor hook that tracks the changes in pointer touch events and detects value of pinch differe | AUTO | | [`useScratch`](./references/useScratch.md) | React sensor hook that tracks state of mouse "scrubs" (or "scratches"). | AUTO | | [`useScroll`](./references/useScroll.md) | React sensor hook that re-renders when the scroll position in a DOM element changes. | AUTO | | [`useScrollbarWidth`](./references/useScrollbarWidth.md) | Hook that will return current browser's scrollbar width. | AUTO | | [`useScrolling`](./references/useScrolling.md) | React sensor hook that keeps track of whether the user is scrolling or not. | AUTO | | [`useSearchParam`](./references/useSearchParam.md) | React sensor hook that tracks browser's location search param. | AUTO | | [`useSize`](./references/useSize.md) | React sensor hook that tracks size of an HTML element. | AUTO | | [`useStartTyping`](./references/useStartTyping.md) | React sensor hook that fires a callback when user starts typing. Can be used | AUTO | | [`useWindowScroll`](./references/useWindowScroll.md) | React sensor hook that re-renders on window scroll. | AUTO | | [`useWindowSize`](./references/useWindowSize.md) | React sensor hook that tracks dimensions of the browser window. | AUTO | ### UI | Hook | Description | Invocation | |------|-------------|------------| | [`useAudio`](./references/useAudio.md) | Creates `