getOwner
Edit this pagegetOwner returns the owner for the currently executing reactive scope.
Import
import { getOwner } from "solid-js";Type
type Owner = unknown;
function getOwner(): Owner | null;The Owner interface is public, but its concrete shape is mostly useful for advanced interop such as runWithOwner.
Parameters
getOwner does not take any parameters.
Return value
- Type:
Owner | null
Returns the current owner or null when no owner is active.
Behavior
getOwnerreturns the current owner and does not create or modify ownership.- Owners determine cleanup and context lookup for descendant computations.
- A computation created inside the current scope becomes part of the current owner tree unless ownership is overridden.
- Component functions run under an owner created for that subtree.
- Calling
getOwnerinside component code returns the owner responsible for rendering and disposing that component subtree. - Turning off tracking with
untrackdoes not create a new owner.
Examples
Capture an owner for later use
import { getOwner, runWithOwner } from "solid-js";
function Example() { const owner = getOwner();
queueMicrotask(() => { if (owner) { runWithOwner(owner, () => { console.log("owner restored"); }); } });
return null;}