createOwner
Creates a plain owner: a scope that adopts the nodes and cleanups created under it and disposes them together.
Creates a plain owner: a scope that adopts the nodes and cleanups created under it and disposes
them together. The building block of createRoot and of control-flow branches.
Import#
ts
import { createOwner } from "@shadow-js/core/extend";
Signature#
ts
function createOwner(parent?: Owner | null): Owner
Parameters#
| Name | Description |
|---|---|
parent |
The owner to attach to and inherit context from. Undefined (or omitted) uses the current owner; null creates a root with no context that only an explicit dispose ends. |
Returns#
The new owner. Dispose it with disposeOwner.
Examples#
ts
import { useEffect } from "@shadow-js/core";
import { createOwner, disposeOwner, runInScope } from "@shadow-js/core/extend";
const branch = createOwner();
runInScope({ owner: branch, listener: null }, () => {
useEffect(() => console.log("branch effect"));
});
disposeOwner(branch); // the effect and its cleanups are gone