currentOwner
// ---------- registers ---------- /** Returns the owner that adopts nodes created right now.
// ---------- registers ----------
/**
Returns the owner that adopts nodes created right now. The extension-API form of getOwner: use
it in a primitive that attaches a node or a cleanup to its caller's owner.
Import#
ts
import { currentOwner } from "@shadow-js/core/extend";
Signature#
ts
function currentOwner(): Owner | null
Returns#
The current owner, or null outside any owner.
Examples#
ts
import { addCleanup, currentOwner } from "@shadow-js/core/extend";
function useInterval(fn: () => void, ms: number): void {
const timer = setInterval(fn, ms);
const owner = currentOwner();
if (owner !== null) addCleanup(owner, () => clearInterval(timer));
}