[]previous and next page

getOwner

Returns the owner that currently adopts new effects, memos and cleanups.

Returns the owner that currently adopts new effects, memos and cleanups. Capture it while a component or root runs, then hand it to runWithOwner from code that runs later.

Import#

ts
import { getOwner } from "@shadow-js/core";

Signature#

ts
function getOwner(): Owner | null

Returns#

The current owner, or null outside any owner (at module scope, or in a callback that runs after an await or a timer).

Examples#

ts
import { getOwner, onCleanup, runWithOwner } from "@shadow-js/core";

function Poller() {
  const owner = getOwner();
  setTimeout(() => {
    runWithOwner(owner, () => onCleanup(() => console.log("poller disposed")));
  }, 1000);
  return null;
}