EffectSchedulerOptions

See source code
Table of contents
interface EffectSchedulerOptions {}

Properties

scheduleEffect

optional

scheduleEffect is a function that will be called when the effect is scheduled.

It can be used to defer running effects until a later time, for example to batch them together with requestAnimationFrame.

scheduleEffect?: (execute: () => void) => void;

Example

let isRafScheduled = false;
const scheduledEffects: Array<() => void> = [];
const scheduleEffect = (runEffect: () => void) => {
  scheduledEffects.push(runEffect);
  if (!isRafScheduled) {
    isRafScheduled = true;
    requestAnimationFrame(() => {
      isRafScheduled = false;
      scheduledEffects.forEach((runEffect) => runEffect());
      scheduledEffects.length = 0;
    });
  }
};
const stop = react(
  "set page title",
  () => {
    document.title = doc.title;
  },
  { scheduleEffect },
);

Prev
ComputedOptions
Next
Reactor