Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/routes/reference/lifecycle/on-mount.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ Non-tracking function executed once on mount.
- By the time `onMount` runs, refs have already been assigned.
- Returning a function from `fn` does not register cleanup. Use [`onCleanup`](/reference/lifecycle/on-cleanup) inside `onMount` when cleanup is needed.

:::note
"Mounted" in Solid refers to when a component is rendered within the reactive tree, not when it is physically inserted into the DOM.
If you store JSX in a variable before conditionally rendering it, `onMount` runs when that JSX is evaluated, even if the elements have not yet been added to the visible page.
Similarly, [`onCleanup`](/reference/lifecycle/on-cleanup) runs based on the reactive ownership tree rather than DOM removal.

For cases where you need to detect actual DOM insertion or removal, consider using a [`ref`](/concepts/refs) callback or the [Lifecycle primitives from solid-primitives](https://github.com/solidjs-community/solid-primitives/tree/main/packages/lifecycle).
:::

## Examples

### Access a ref after mount
Expand Down
Loading