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
Back to the full SolidJS cheat sheet