# touchable-hook

> a react hook that emulates native touch behaviour for things like buttons, list items, and more

Latest version **1.3.0** (published 2019-05-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install touchable-hook
pnpm add touchable-hook
yarn add touchable-hook
bun add touchable-hook
```

## 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 | 1.3.0 |
| Published | 2019-05-21 |
| First published | 2019-05-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 49.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 34 |
| Author | Ben McMahen |
| Maintainers | bmcmahen |
| Keywords | react, hook, touch, gesture |

## Links

- npm: https://www.npmjs.com/package/touchable-hook
- Repository: https://github.com/bmcmahen/touchable-hook
- Issues: https://github.com/bmcmahen/touchable-hook/issues
- npm.io page: https://npm.io/package/touchable-hook

## Dependencies (3)

- [tslib](https://npm.io/package/tslib.md) ^1.9.3
- [@types/react](https://npm.io/package/@types/react.md) ^16.8.10
- [@types/react-dom](https://npm.io/package/@types/react-dom.md) ^16.8.3

## 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

- 1.3.0 (latest) — 2019-05-21
- 1.2.1 — 2019-05-07
- 1.2.0 — 2019-05-07
- 1.1.3 — 2019-05-05
- 1.1.2 — 2019-05-03
- 1.1.1 — 2019-05-03
- 1.1.0 — 2019-05-03
- 1.0.8 — 2019-05-03
- 1.0.7 — 2019-05-03
- 1.0.6 — 2019-05-03
- 1.0.5 — 2019-05-03
- 1.0.4 — 2019-05-03
- 1.0.3 — 2019-05-02
- 1.0.2 — 2019-05-02
- 1.0.1 — 2019-05-02
- … 1 more at https://npm.io/package/touchable-hook/versions

## README

<div align="center">
    
# touchable-hook
  
[![npm package](https://img.shields.io/npm/v/touchable-hook/latest.svg)](https://www.npmjs.com/package/touchable-hook)
[![Follow on Twitter](https://img.shields.io/twitter/follow/benmcmahen.svg?style=social&logo=twitter)](
https://twitter.com/intent/follow?screen_name=benmcmahen
)

</div>

`touchable-hook` provides a react hook that emulates native touch behaviour for building performant, customizable interactive widgets like buttons, list items, etc. It's a limited implementation of the touchable interface found in [react-native-web](https://github.com/necolas/react-native-web/). It provides the basic touchable behaviour for [Sancho-UI](https://github.com/bmcmahen/sancho) and is built using [react-gesture-responder](https://github.com/bmcmahen/react-gesture-responder).

## Why?

When building mobile web apps it's challenging to get interactive elements to **feel** just right. Using this hook makes it easier:

- **hover state is provided only when using a mouse**.
- **active state is available after a configurable delay**. This is useful for avoiding highlighting list elements when scrolling, but providing immediate visual feedback on elements like buttons.
- **mouse and touch support**.
- **keyboard support** which emulates both button and anchor behaviour.
- **long press support**

## Install

Install both `touchable-hook` and `react-gesture-responder` using yarn or npm.

```
yarn add touchable-hook react-gesture-responder
```

```js
import { useTouchable } from "touchable-hook";

function TouchableHighlight({ onPress, onLongPress }) {
  const { bind, active, hover } = useTouchable({
    onPress,
    onLongPress,
    behavior: "button" // or 'link'
  });

  return (
    <div role="button" tabIndex={0} {...bind}>
      This is a touchable highlight
    </div>
  );
}
```

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