defer

Commons
stable

Schedules a callback after a given timeout (ms) using window.setTimeout in the browser. When called during SSR or with timeout = 0, the callback runs synchronously. Returns a cancel function.

API

Signature

Signature TypeScript complète, extraite du fichier util.

typescript

API

Paramètres

Paramètres d'entrée acceptés par cet util.

timeout
requis
number
Delay in milliseconds before the callback is invoked. Pass 0 to run synchronously.
cb
requis
() => void
The function to call after the timeout.

API

Valeur de retour

La valeur retournée par cet util.

A cancel function. Calling it clears the pending timeout so the callback is never invoked.

Usage

Exemples

Extraits de code prêts à coller.

Delayed execution with cancel

typescript