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

https://github.com/seonhyungjo/use-delay

⏳Easy Throttle, Debounds Hooks
https://github.com/seonhyungjo/use-delay

debounds delay hooks react throttle

Last synced: about 1 year ago
JSON representation

⏳Easy Throttle, Debounds Hooks

Awesome Lists containing this project

README

          


React useDelay Logo

React useDelay Hooks

[![NPM](https://img.shields.io/npm/v/use-delay.svg)](https://www.npmjs.com/package/use-delay) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)

React useDelay example

## Install

```bash
npm install --save use-delay
```

## Usage

```tsx
import React, { useCallback, useState } from 'react'
import { useThrottle, useDebounds } from 'use-delay'

const App = () => {
const [throttleCount, setThrottleCount] = useState(0);
const [deboundsCount, setDeboundsCount] = useState(0);
const actionThrottleHandle = useCallback(() => {
setThrottleCount(throttleCount + 1)
})

const actionDeboundsHandle = useCallback(() => {
setDeboundsCount(deboundsCount + 1)
})

const onTrottle = useThrottle(1000, actionThrottleHandle)
const onDebounds = useDebounds(1000, actionDeboundsHandle)

return (




{`throttle count ${throttleCount}`}


throttle



{`debounds count ${deboundsCount}`}


debounds



)
}
export default App
```

```css

* {
box-sizing: border-box;
}

.outerDiv {
display: block;
width: 100%;
height: 500px;
overflow-x: hidden;
overflow-y: scroll;
border: 1px solid #000
}

.throttleDiv {
display: inline-block;
width: 50%;
height: 500px;
overflow-x: hidden;
overflow-y: scroll;
border: 1px solid red;
}

.deboundsDiv {
display: inline-block;
width: 50%;
height: 500px;
overflow-x: hidden;
overflow-y: scroll;
border: 1px solid blue;
}

.innerDiv {
width: 100px;
height: 100px;
border: 1px solid green;

margin-top: 1500px;
}

.fixcount {
position: fixed;
}
```

## License

MIT © :mouse:[snyung](https://github.com/seonhyungjo)

---

This hook is created using [create-react-hook](https://github.com/hermanya/create-react-hook).