Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/*
* Utility to only call Redux updates in RequestAnimationFrame's
* Also uses React-dom's batchedUpdates
*/
import raf from 'raf';
import { unstable_batchedUpdates as batchedUpdates } from 'react-dom';
let rafID;
let notifyFunc;
function animFrame() {
if (notifyFunc) {
batchedUpdates(notifyFunc);
notifyFunc = null;
}
rafID = raf(animFrame);
}
export default function rafUpdateBatcher(notify) {
if (rafID === undefined) rafID = raf(animFrame);
notifyFunc = notify;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment