Skip to content

Latest commit

 

History

History
29 lines (22 loc) · 785 Bytes

File metadata and controls

29 lines (22 loc) · 785 Bytes
title onMount
order 5

Registers a method that runs after initial rendering is done and the elements are mounted to the page. Ideal for using refs and managing other one-time setup that requires the

function onMount(fn: () => void): void

This is an alias for an effect that is non-tracking, meaning that it is equivalent to a createEffect with no dependencies.

// example that shoes how to use onMount to get a ref to an element
import { onMount } from "solid-js"

function MyComponent() {
	let ref: HTMLDivElement

	// when the component is mounted, the button will be disabled
	onMount(() => {
		ref.disabled = true
	})
	return <button ref={ref}>Focus me!</button>
}