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.
- Host: GitHub
- URL: https://github.com/soywod/react-use-debounce
- Owner: soywod
- License: mit
- Created: 2020-08-17T16:29:29.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2020-08-18T10:46:10.000Z (about 5 years ago)
- Last Synced: 2024-12-15T22:29:09.782Z (10 months ago)
- Language: TypeScript
- Homepage:
- Size: 110 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# ⏳ React use debounce [](https://www.npmjs.com/package/@soywod/react-use-debounce) [](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,
) => Debouncetype 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
```