# @render-props/debounce

> A state container which limits the frequency with which setState can be called using lodash's debounce function. By default, `setState` is invoked on the trailing edge of the debounce call. If `leading` and `trailing` options are `true`, func is invoked

Latest version **0.1.13** (published 2019-03-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install @render-props/debounce
pnpm add @render-props/debounce
yarn add @render-props/debounce
bun add @render-props/debounce
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.13 |
| Published | 2019-03-20 |
| First published | 2018-02-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 22.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 36 |
| Author | Jared Lunde |
| Maintainers | jaredlunde |
| Keywords | react, render props, function as child, hoc, state container, debounce |

## Links

- npm: https://www.npmjs.com/package/@render-props/debounce
- Repository: https://github.com/jaredlunde/render-props/tree/master/packages/debounce
- npm.io page: https://npm.io/package/@render-props/debounce

## Dependencies (2)

- [@babel/runtime](https://npm.io/package/@babel/runtime.md) ^7.4.0
- [@render-props/utils](https://npm.io/package/@render-props/utils.md) ^0.2.0

## 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.1.13 (latest) — 2019-03-20
- 0.1.12 — 2019-01-31
- 0.1.11 — 2019-01-12
- 0.1.10 — 2018-12-29
- 0.1.9 — 2018-09-11
- 0.1.8 — 2018-09-10
- 0.1.7 — 2018-08-21
- 0.1.6 — 2018-08-20
- 0.1.5 — 2018-08-18
- 0.1.4 — 2018-08-18
- 0.1.3 — 2018-08-18
- 0.1.2 — 2018-03-22
- 0.1.1 — 2018-02-08
- 0.1.0 — 2018-02-05

## README

# Debounce
A state container which limits the frequency with which setState can be called
using lodash's debounce function. By default, `setState` is invoked on the
trailing edge of the debounce call.  If `leading` and `trailing` options are `true`,
func is invoked on the trailing edge of the timeout only if the debounced
function is invoked more than once during the `wait` timeout.

[See lodash's documentation for more details](https://lodash.com/docs/4.17.4#debounce)

![Debouncing example image](https://image.slidesharecdn.com/5fastcordova-140116132650-phpapp02/95/fast-cordova-applications-27-638.jpg?cb=1389879297)


### Installation
```yarn add @render-props/debounce``` or ```npm i @render-props/debounce```

____


## Usage
```js
import Debounce from '@render-props/debounce'


function DebouncedBodyScroller () {
  return (
    <Debounce initialState={{scrollY: 0, gt30: false}}>
      {({debounceState, state}) => (
        <body
          onScroll={
            e => debounceState(
              prevState => (
                window.scrollY > 30
                ? {gt30: true, scrollY: window.scrollY}
                : {gt30: false, scrollY: window.scrollY}
              )
            )
          }
        >
          Greater than 30? {String(state.gt30)}
        </body>
      )}
    </Debounce>
  )
}
```

____


## Props
- `initialState {object}`: the state which this component should initialize with. This component is NOT controlled so you cannot update the state of this component by changing the property value here.
- `wait {number}`: number of milliseconds to delay
- `maxWait {number}`: maximum time func is allowed to be delayed before it's invoked
- `leading {bool}`: invokes function on the leading edge of the timeout
- `traililng {bool}`: invokes function on the trailing edge of the timeout


## Render Props

#### Methods
- `debounceState`: this function is setState wrapped in lodash's debounce function.

#### State
- `state {object}`: in addition to the `debounceState` method, this component provides the state exactly as its been set using `debounceState`

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