# use-debounce-react

> A react hook which is wait until something is happening then execute provided callback

Latest version **1.0.0** (published 2023-01-27) · ISC license · 0 weekly downloads

## Install

```sh
npm install use-debounce-react
pnpm add use-debounce-react
yarn add use-debounce-react
bun add use-debounce-react
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2023-01-27 |
| First published | 2023-01-27 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 4.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Ravi Verma |
| Maintainers | ravi-verma |
| Keywords | debounce, use-debounce, wait, watching, typing, use-debounce-react, react debounce, useDebounce, useDebounce hook, usedebounce hook, react hooks, delay, react delay, ravi verma |

## Links

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

## Alternatives

- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads
- [fa](https://npm.io/package/fa.md) — 185 weekly downloads

## Recent versions

- 1.0.0 (latest) — 2023-01-27

## README

# useDebounce (A ReactJS Hook)



## This is a react-JS hook.

It is basically useful to add **debounce/delay** until some task is happening, once the task will be done then provided **callback** will be executed.



### Debounced provided callback function for particular interval

```js
import { useDebounce } from "use-debounce-rv/dist";

const { Debounce } = useDebounce();

Debounce(() => {}, 1000);
```

# Installation

```js
npm i use-debounce-rv
```

or

```js
npm i --legacy-peer-deps use-debounce-rv
```

## Usage example

### Import Hook

    import { useDebounce } from  'use-debounce-rv/dist';

### Define Hook

    const { Debounce } = useDebounce();

### Usage

> Debounce(callback, interval)

-  **callback**: _A function to execute after particular interval._
-  **interval**: _Time in milli seconds._


    Debounce(() => {}, 1000);

## Example -01 (Execute a callback after typing finished)

```js
import { useDebounce } from "use-debounce-rv/dist";

export const SamplePage = () => {
	const [data, setData] = useState();
	const { Debounce } = useDebounce();

	const handleChange = (e) => {
		setData(e.target.value);
		//Debounce(callback, interval)
		//Debounce(() => {}, 1000);
		Debounce(() => {
			console.log("side effect after typing finshed");
		}, 1500);
	};
	return (
		<div>
			<label>Search Data</label>
			<input type="text" value={data} onChange={handleChange} />
		</div>
	);
};
```

> In above example Debounce will execute the console.log once user ends typing.

## Example - 02 (Add delay in function execution)

```js
import { useDebounce } from "use-debounce-rv/dist";

export const SamplePage = () => {
	const { Debounce } = useDebounce();

	const handleClick = (e) => {
		//Debounce(callback, interval)
		//Debounce(() => {}, 1000);
		Debounce(() => {
			console.log("I am executed after 2 second");
		}, 2000);
	};
	return (
		<div>
			<label>Click The Button </label>
			<button onChange={handleClick}>Hey! Click Me</button>
		</div>
	);
};
```

> In above example Debounce will execute the console.log after 2 second.

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