createRoot
Edit this pageimport { createRoot } from "solid-js"
function createRoot<T>(fn: (dispose: () => void) => T): TCreates a new non-tracked owner scope that doesn't auto-dispose. This is useful for nested tracking scopes that you do not wish to release when the parent re-evaluates.
All Solid code should be wrapped in one of these top level as they ensure that all memory/computations are freed up. Normally you do not need to worry about this as createRoot is embedded into all render entry functions.
Solid 2.0 — Roots owned by parent
In Solid 2.0, a root created inside an owned scope is disposed with the parent. To create a fully detached root (one that won't be disposed when the parent is), use runWithOwner(null, ...):
import { runWithOwner } from "solid-js"
// Detached root — not disposed with the parentrunWithOwner(null, () => { createRoot((dispose) => { // This root is independent of any parent scope // Must be manually disposed })})