tryOnScopeDispose

Commons
stable

Safely register a cleanup callback with onScopeDispose(). When called outside an active effect scope the function is ignored and returns false, preventing the "getCurrentScope is undefined" error.

API

Signature

Signature TypeScript complète, extraite du fichier util.

typescript

API

Paramètres

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

fn
requis
TFn
The cleanup callback to register. Called when the current effect scope is disposed (e.g. component unmount).

API

Valeur de retour

La valeur retournée par cet util.

true when the callback was successfully registered inside an active scope; false when there is no active scope and the callback was skipped.

Usage

Exemples

Extraits de code prêts à coller.

Cleanup inside and outside a scope

typescript