This is possible if you use something like Browserify or webpack to create a React from CommonJS environment or otherwise create a custom React assembly. That is, you cannot do this if you are using only a downloadable, pre-built React.
Check out the Pete Hunt project-raf-batching project for a more complete solution (including RAF policies), but here is a minimal example for this:
var ReactUpdates = require("react/lib/ReactUpdates"); var rafBatchingStrategy = { isBatchingUpdates: true, batchedUpdates: function(callback, param) { callback(param); } }; var tick = function() { ReactUpdates.flushBatchedUpdates(); requestAnimationFrame(tick); }; requestAnimationFrame(tick); ReactUpdates.injection.injectBatchingStrategy(rafBatchingStrategy);
Michelle tilley
source share