# @react-hook/hover

> A React hook for tracking the hover state of DOM elements in browsers where hovering is possible

Latest version **4.0.0** (published 2020-06-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install @react-hook/hover
pnpm add @react-hook/hover
yarn add @react-hook/hover
bun add @react-hook/hover
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.0.0 |
| Published | 2020-06-07 |
| First published | 2019-04-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 23.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1530 |
| Author | Jared Lunde |
| Maintainers | jaredlunde |
| Keywords | react, react hook, hook, react hooks, hooks, hover, use hover, usehover |

## Links

- npm: https://www.npmjs.com/package/@react-hook/hover
- Repository: https://github.com/jaredLunde/react-hook
- Homepage: https://github.com/jaredLunde/react-hook/tree/master/packages/hover#readme
- Issues: https://github.com/jaredLunde/react-hook/issues
- npm.io page: https://npm.io/package/@react-hook/hover

## Dependencies (1)

- [@react-hook/event](https://npm.io/package/@react-hook/event.md) ^1.2.1

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 4.0.0 (latest) — 2020-06-07
- 3.1.1 — 2020-06-07
- 3.1.0 — 2020-06-07
- 3.0.2 — 2020-06-04
- 3.0.1 — 2020-05-28
- 3.0.0 — 2020-05-28
- 2.2.0 — 2020-05-25
- 2.1.0 — 2020-03-24
- 2.0.1 — 2019-11-26
- 2.0.0 — 2019-11-26
- 1.0.1 — 2019-04-03
- 1.0.0 — 2019-04-03

## README

<hr>
<div align="center">
  <h1 align="center">
    useHover()
  </h1>
</div>

<p align="center">
  <a href="https://bundlephobia.com/result?p=@react-hook/hover">
    <img alt="Bundlephobia" src="https://img.shields.io/bundlephobia/minzip/@react-hook/hover?style=for-the-badge&labelColor=24292e">
  </a>
  <a aria-label="Types" href="https://www.npmjs.com/package/@react-hook/hover">
    <img alt="Types" src="https://img.shields.io/npm/types/@react-hook/hover?style=for-the-badge&labelColor=24292e">
  </a>
  <a aria-label="NPM version" href="https://www.npmjs.com/package/@react-hook/hover">
    <img alt="NPM Version" src="https://img.shields.io/npm/v/@react-hook/hover?style=for-the-badge&labelColor=24292e">
  </a>
  <a aria-label="License" href="https://jaredlunde.mit-license.org/">
    <img alt="MIT License" src="https://img.shields.io/npm/l/@react-hook/hover?style=for-the-badge&labelColor=24292e">
  </a>
</p>

<pre align="center">npm i @react-hook/hover</pre>
<hr>

A React hook for tracking the hover state of DOM elements in browsers
where hovering is possible. If the browser does not support hover states
(e.g. a phone) the `isHovering` value will always be `false`.

## Quick Start

[Check out the example on **CodeSandbox**](https://codesandbox.io/s/react-hookhover-example-oohtc)

```jsx harmony
import * as React from 'react'
import useHover from '@react-hook/hover'

const Component = (props) => {
  const target = React.useRef(null)
  const isHovering = useHover(target, {enterDelay: 200, leaveDelay: 200})
  return <div ref={target}>{isHovering ? 'Hovering' : 'Not hovering'}</div>
}
```

## API

### useHover(target, options?)

```tsx
function useHover<T extends HTMLElement>(
  target: React.RefObject<T> | T | null,
  options: UseHoverOptions = {}
): boolean
```

#### Arguments

| Argument | Type                                                 | Required? | Description                                                                          |
| -------- | ---------------------------------------------------- | --------- | ------------------------------------------------------------------------------------ |
| target   | <code>React.RefObject<T> &#124; T &#124; null</code> | Yes       | A React ref created by `useRef()` or an HTML element                                 |
| options  | [`UseHoverOptions`](#usehoveroptions)                | Yes       | Configuration options for the hook. See [`UseHoverOptions`](#usehoveroptions) below. |

#### Returns `boolean`

This hook returns `true` if the element in `ref` is in a hover state, otherwise `false`. This value
is always `false` on devices that don't have hover states, i.e. phones.

#### UseHoverOptions

| Property   | Type   | Description                                                    |
| ---------- | ------ | -------------------------------------------------------------- |
| enterDelay | number | Delays setting `isHovering` to `true` for this amount in `ms`  |
| leaveDelay | number | Delays setting `isHovering` to `false` for htis amount in `ms` |

## LICENSE

MIT

---
_Source: https://npm.io/package/@react-hook/hover · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
