Docs
Virtual DOM
Advanced
batch()

batch()

Syntax: batch(timer)
Example: batch()

You can use batch to reschedule requestAnimationFrame and reduce unnecessary rerenders in short intervals. It accepts a timer as a number and returns a callback queuer function.

Note that batch is should not be abused for every operation. Using it for every operation may delay the rendering of the page. Additionally, functionality may break if you specify a custom oldVNode for each operation.

batch works best when renders occur in rapid succession:

import { _, m, batch, render } from 'million';

const queueRender = batch();

queueRender(() => render(document.body, <div>I'm not rendered</div>));
queueRender(() => render(document.body, <div>I'm not rendered</div>));
queueRender(() => render(document.body, <div>I'm rendered!</div>));
Last updated on July 28, 2022