Who becomes an owner
The current owner adopts whatever is created while it is current: effects, memos, cleanups, error handlers and child roots.
The current owner adopts whatever is created while it is current: effects, memos, cleanups, error handlers and child roots.
| Created by | Becomes | Disposed when |
|---|---|---|
createRoot(fn) |
a root, child of the current owner | dispose() is called, or the parent is disposed |
createRoot(fn, { detached: true }) |
a root with no parent | only through its own dispose() |
useEffect, useRenderEffect, onMount |
an effect | its owner is disposed |
useMemo |
a memo | its owner is disposed |
catchError(fn, handler) |
a scope | its owner is disposed |
render(code, container) / hydrate(...) |
a root (the returned function disposes it) | you call the function |
A component call (createComponent) |
an owner, child of the owner current at the call site | the enclosing owner is disposed |
A For row or mapArray row |
a root per row | the row's key leaves the list, or the list's owner is disposed |
A Show/Switch branch |
children of the branch memo | the selection changes |
Every component gets an owner of its own. createComponent creates a child of the owner that is current at the call site and runs the component function untracked inside it. Effects and cleanups a component creates therefore belong to that component's owner, which lives exactly as long as the enclosing scope (the root of render(), a branch, a row): a component is never disposed on its own, and there is no unmount hook beyond onCleanup.