# @react-cmpt/use-throttle

> The throttled value / function hook for react

Latest version **0.3.3** (published 2022-01-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install @react-cmpt/use-throttle
pnpm add @react-cmpt/use-throttle
yarn add @react-cmpt/use-throttle
bun add @react-cmpt/use-throttle
```

## Health

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

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

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.3 |
| Published | 2022-01-12 |
| First published | 2020-04-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 20.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | wangcch |
| Maintainers | wangcch |
| Keywords | react, hooks, use, throttle, useThrottle, useThrottleFn, use-throttle, callback |

## Links

- npm: https://www.npmjs.com/package/@react-cmpt/use-throttle
- Repository: https://github.com/react-cmpt/use-throttle
- Homepage: https://github.com/react-cmpt/use-throttle#readme
- Issues: https://github.com/react-cmpt/use-throttle/issues
- npm.io page: https://npm.io/package/@react-cmpt/use-throttle

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

- 0.3.3 (latest) — 2022-01-12
- 0.3.2 — 2021-04-10
- 0.3.1 — 2021-04-05
- 0.3.0 — 2020-09-29
- 0.2.2 — 2020-06-28
- 0.2.1 — 2020-06-02
- 0.2.0 — 2020-04-26
- 0.1.1 — 2020-04-23
- 0.1.0 — 2020-04-19
- 0.1.0-alpha2 — 2020-04-16
- 0.1.0-alpha — 2020-04-10

## README

# use-throttle

The throttled value / function hook for react

[![CI](https://github.com/react-cmpt/use-throttle/workflows/CI/badge.svg?branch=master)](https://github.com/react-cmpt/use-throttle/actions?query=workflow%3ACI)
[![npm](https://img.shields.io/npm/v/@react-cmpt/use-throttle.svg)](https://www.npmjs.com/package/@react-cmpt/use-throttle)
[![GitHub license](https://img.shields.io/github/license/react-cmpt/use-throttle)](https://github.com/react-cmpt/use-throttle/blob/master/LICENSE)
[![minzip](https://badgen.net/bundlephobia/minzip/@react-cmpt/use-throttle)](https://bundlephobia.com/package/@react-cmpt/use-throttle)

## Usage

### Installation

```shell
yarn add @react-cmpt/use-throttle
```

### codesandbox

[![Edit use-throttle-example](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/use-throttle-example-i1xz0?fontsize=14&hidenavigation=1&theme=dark)

### useThrottle

throttled value

<table>
  <tr>
    <th colspan="2">option</th>
    <th>type</th>
    <th>default</th>
    <th>explain</th>
  </tr>
  <tr>
    <td colspan="2">value</td>
    <td>any</td>
    <td>-</td>
    <td>The value to throttle.</td>
  </tr>
  <tr>
    <td colspan="2">wait</td>
    <td>number</td>
    <td>0</td>
    <td>The number of milliseconds to throttle invocations to.</td>
  </tr>
  <tr>
    <td rowspan="2">options</td>
    <td>leading</td>
    <td>boolean</td>
    <td><code>false</code></td>
    <td>Specify invoking on the leading edge of the timeout.</td>
  </tr>
  <tr>
    <td>customizer</td>
    <td>function</td>
    <td>-</td>
    <td>The function to customize comparisons.</td>
  </tr>
</table>

| return      | type     | explain                          |
| ----------- | -------- | -------------------------------- |
| value       | any      | Returns the new throttled value. |
| cancel      | function | The clear timer function.        |
| callPending | function | The callback manually function.  |

```tsx
import { useThrottle } from "@react-cmpt/use-throttle";

const Demo = ({ value }) => {
  const [tValue, { cancel, callPending }] = useThrottle(value, 200);

  // ...
};
```

### useThrottleFn

throttled function

<table>
  <tr>
    <th colspan="2">option</th>
    <th>type</th>
    <th>default</th>
    <th>explain</th>
  </tr>
  <tr>
    <td colspan="2">fn</td>
    <td>function</td>
    <td>-</td>
    <td>The function to throttle.</td>
  </tr>
  <tr>
    <td colspan="2">wait</td>
    <td>number</td>
    <td>0</td>
    <td>The number of milliseconds to throttle invocations to.</td>
  </tr>
  <tr>
    <td rowspan="1">options</td>
    <td>leading</td>
    <td>boolean</td>
    <td><code>false</code></td>
    <td>Specify invoking on the leading edge of the timeout.</td>
  </tr>
</table>

| return      | type     | explain                         |
| ----------- | -------- | ------------------------------- |
| callback    | function | The new throttled function.     |
| cancel      | function | The clear timer function.       |
| callPending | function | The callback manually function. |

```tsx
import { useThrottleFn } from "@react-cmpt/use-throttle";

const Demo = () => {
  const { callback, cancel, callPending } = useThrottleFn(() => {
    console.log("click");
  }, 200);

  return <button onClick={callback}>++</button>;
};
```

> useDebounce, useDebounceCallback -> [use-debounce](https://github.com/xnimorz/use-debounce)

## Dev

```shell
# build package
yarn build

# tests
yarn test

# lint
yarn lint
```

## License

[MIT](./LICENSE)

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