Reactive Utilities


Edit this page
import { getOwner } from "solid-js"
import type { Owner } from "solid-js"
function getOwner(): Owner

Gets the reactive scope that owns the currently running code, e.g., for passing into a later call to runWithOwner outside of the current scope.

Internally, computations (effects, memos, etc.) create owners which are children of their owner, all the way up to the root owner created by createRoot or render. In particular, this ownership tree lets Solid automatically clean up a disposed computation by traversing its subtree and calling all onCleanup callbacks. For example, when a createEffect's dependencies change, the effect calls all descendant onCleanup callbacks before running the effect function again. Calling getOwner returns the current owner node that is responsible for disposal of the current execution block.

Components are not computations, so do not create an owner node, but they are typically rendered from a createEffect which does, so the result is similar: when a component gets unmounted, all descendant onCleanup callbacks get called. Calling getOwner from a component scope returns the owner that is responsible for rendering and unmounting that component.

Note that the owning reactive scope isn't necessarily tracking. For example, untrack turns off tracking for the duration of a function (without creating a new reactive scope), as do components created via JSX (<Component ...>).

Report an issue with this page