Refs & Forwarding in SolidJS
From the SolidJS cheat sheet ยท Refs & DOM Access ยท verified Jul 2026
Refs & Forwarding
Get direct access to DOM elements using ref and forward refs to parent components.
tsx
// Quick Reference
let inputRef!: HTMLInputElement;
<input ref={inputRef} />
// Or with callback: <input ref={(el) => doSomething(el)} />๐ก Use the ! (definite assignment) operator since refs are assigned after render
โก Callback refs run immediately when the element is created โ useful for canvas setup
๐ Access refs in onMount, not in the component body โ the element may not exist yet
๐ข Forward refs by passing them as regular props โ no special forwardRef API needed
refsdomelements