f365.setTimeout / setInterval, tracked timers

Form-scoped timers that auto-cleanup on unmount. Prefer these over bare window.setTimeout to avoid leaks across navigations.

f365.setTimeout, f365.setInterval, and their clear* counterparts are drop-in replacements for the window variants, except they're tracked by the form runtime and automatically cleared on form unmount.

Why use them

Inside an SPFx form customizer, the SP page navigates between forms without a full browser reload. A bare window.setTimeout set in form A keeps firing after the user has moved to form B, likely causing console errors or worse, calls against fields that no longer exist.

The f365.setTimeout family avoids this. Inside form-level + per-field event JS, the bare setTimeout / setInterval identifiers are shadowed via new Function argument injection, so even authors who forget to use the namespaced helper get the safe version.

Surface

PropertyDescription
f365.setTimeout(fn, ms)Returns an id usable with clearTimeout.
f365.setInterval(fn, ms)Returns an id usable with clearInterval.
f365.clearTimeout(id) / clearInterval(id)Cancel manually.

Example

Debounce a save-on-change

let pending: number | undefined;
f365.events.onChange('Notes', () => {
  if (pending) f365.clearTimeout(pending);
  pending = f365.setTimeout(() => f365.http.post('/api/draft', f365.data()), 500);
});