An open API service indexing awesome lists of open source software.

https://github.com/soywod/react-use-debounce

⏳ React hook that safely add debounce to any kind of handler.
https://github.com/soywod/react-use-debounce

Last synced: 8 months ago
JSON representation

⏳ React hook that safely add debounce to any kind of handler.

Awesome Lists containing this project

README

          

# ⏳ React use debounce [![npm](https://img.shields.io/npm/v/@soywod/react-use-debounce?label=npm)](https://www.npmjs.com/package/@soywod/react-use-debounce) [![gh-actions](https://github.com/soywod/react-use-debounce/workflows/tests/badge.svg)](https://github.com/soywod/react-use-debounce/actions?query=workflow%3Atests)

React hook that safely add debounce to any kind of handler.

## Installation

```bash
npm install @soywod/react-use-debounce
# or
yarn add @soywod/react-use-debounce
```

## Definition

```typescript
type UseDebounce = (
fn: T,
opts?: number | Partial,
) => Debounce

type DebounceOpts = {
delay: number
persist: boolean
}

type Debounce = {
(...params: Parameters): void
abort: () => void
terminate: () => void
}
```

## Usage

```typescript
import useDebounce from "@soywod/react-use-debounce"

function Component() {
const handler = useDebounce(() => console.log("Hello!"))

return (
<>

Say hello with delay


Abort


Terminate

>
)
}
```

## Development

```bash
git clone https://github.com/soywod/react-use-debounce.git
cd react-use-debounce
yarn install
```

## Tests

```bash
yarn test
```