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

https://github.com/tj/react-batch

Batch component for performant frequent updates (flush on count or interval)
https://github.com/tj/react-batch

react react-component

Last synced: 5 months ago
JSON representation

Batch component for performant frequent updates (flush on count or interval)

Awesome Lists containing this project

README

          

# React Batch

Batches and flushes renders based on the number of items available. Useful for large lists of frequently updated items which would otherwise cause performance problems with React's sync rendering.

## Installation

```
$ yarn add tj/react-batch
```

## Properties

- `count`: the number of items available for rendering __(required)__
- `flushCount`: render after a given number of items __(required)__
- `flushInterval`: render after a given interval is exceeded __(required)__
- `render`: render callback __(required)__
- `debug`: enable debug logging

## Example

```js
class BatchExample extends Component {
constructor() {
super()
this.list = this.list.bind(this)
this.state = { items: [] }
this.renders = 0
}

async componentDidMount() {
while (1) {
const prev = this.state.items
const items = [`Hello World #${prev.length}`, ...prev]
this.setState({ items })
await sleep(Math.random() * 30)
}
}

list() {
const { items } = this.state

return


Count: {items.length}


Renders: {this.renders++}



    {items.map((v, i) =>
  • {v}
  • )}


}

render() {
return
}
}
```

---

![](https://img.shields.io/badge/license-MIT-blue.svg)
![](https://img.shields.io/badge/status-stable-green.svg)