SolidJS
A comprehensive cheat sheet for SolidJS, the reactive JavaScript framework with fine-grained reactivity, signals, stores, and control flow components.
Components & JSX
SolidJS components are plain functions that run once. JSX compiles to real DOM operations, not a virtual DOM.
Components are functions that return JSX. They execute only once — reactivity handles updates.
// Quick Reference
const Greeting = (props) => {
return <h1>Hello {props.name}</h1>;
};
// Usage: <Greeting name="SolidJS" />Handle DOM events with on-prefixed attributes and native event delegation.
// Quick Reference
<button onClick={() => console.log("clicked")}>Click</button>
<input onInput={(e) => setValue(e.currentTarget.value)} />Signals
Signals are the core reactive primitive in SolidJS. They hold values and automatically track dependencies.
Create a reactive signal that returns a getter function and a setter function.
// Quick Reference
import { createSignal } from "solid-js";
const [count, setCount] = createSignal(0);
console.log(count()); // 0
setCount(5); // set directly
setCount(prev => prev + 1); // functional updateCreate computed values by wrapping signal reads in a function — no special API needed.
// Quick Reference
const [count, setCount] = createSignal(0);
const doubled = () => count() * 2;
// doubled() auto-updates when count changesControl Flow
SolidJS uses components for control flow instead of JavaScript expressions to maintain fine-grained reactivity.
Conditionally render with Show and efficiently iterate lists with For.
// Quick Reference
import { Show, For } from "solid-js";
<Show when={loggedIn()} fallback={<Login />}>
<Dashboard />
</Show>
<For each={items()}>{(item) => <li>{item.name}</li>}</For>Multi-condition rendering with Switch/Match and primitive-keyed iteration with Index.
// Quick Reference
import { Switch, Match, Index } from "solid-js";
<Switch fallback={<p>Not found</p>}>
<Match when={route() === "home"}><Home /></Match>
<Match when={route() === "about"}><About /></Match>
</Switch>Effects & Memos
Effects run side effects in response to signal changes. Memos cache derived values for performance.
Run a side effect that automatically re-executes when its signal dependencies change.
// Quick Reference
import { createSignal, createEffect } from "solid-js";
const [count, setCount] = createSignal(0);
createEffect(() => {
console.log("Count is:", count());
});Create a cached derived value that only recomputes when its dependencies change.
// Quick Reference
import { createSignal, createMemo } from "solid-js";
const [count, setCount] = createSignal(0);
const isEven = createMemo(() => count() % 2 === 0);
console.log(isEven()); // trueProps Utilities
SolidJS props are reactive getters. Use mergeProps, splitProps, and children() to work with them safely.
Set default props with mergeProps and separate local from pass-through props with splitProps.
// Quick Reference
import { mergeProps, splitProps } from "solid-js";
// Default props
const merged = mergeProps({ color: "blue" }, props);
// Split props into groups
const [local, others] = splitProps(props, ["class", "style"]);Resolve and manipulate children reactively with the children() utility.
// Quick Reference
import { children } from "solid-js";
import type { ParentProps } from "solid-js";
const List = (props: ParentProps) => {
const resolved = children(() => props.children);
return <ul>{resolved()}</ul>;
};Lifecycle
SolidJS lifecycle hooks for setup and cleanup within components.
Run code after the component mounts or when it unmounts.
// Quick Reference
import { onMount, onCleanup } from "solid-js";
onMount(() => {
console.log("Component mounted");
});
onCleanup(() => {
console.log("Component unmounted");
});Context
Share reactive state across the component tree without prop drilling.
Create and consume context to share state across deeply nested components.
// Quick Reference
import { createContext, useContext } from "solid-js";
const ThemeCtx = createContext("light");
// Provider: <ThemeCtx.Provider value="dark">
// Consumer: const theme = useContext(ThemeCtx);Stores
Stores provide reactive state for nested objects and arrays with fine-grained updates.
Create a reactive store for complex nested state with path-based updates.
// Quick Reference
import { createStore } from "solid-js/store";
const [state, setState] = createStore({ count: 0, user: { name: "Alice" } });
setState("count", 1);
setState("user", "name", "Bob");Use produce for mutable-style updates and reconcile for replacing store data.
// Quick Reference
import { createStore, produce, reconcile } from "solid-js/store";
setState(produce(s => { s.user.name = "Bob"; }));
setState(reconcile(newData));Refs & DOM Access
Access and manipulate DOM elements directly using refs and directives.
Get direct access to DOM elements using ref and forward refs to parent components.
// Quick Reference
let inputRef!: HTMLInputElement;
<input ref={inputRef} />
// Or with callback: <input ref={(el) => doSomething(el)} />Resources & Data Fetching
createResource provides a reactive way to handle async data with built-in loading and error states.
Fetch async data reactively with automatic loading/error tracking and optional source signals.
// Quick Reference
import { createResource } from "solid-js";
const [data] = createResource(fetchData);
// data(), data.loading, data.errorPortals & Error Boundaries
Render content outside the component tree and handle errors declaratively.
Render components into a different DOM node and catch errors in the component tree.
// Quick Reference
import { Portal } from "solid-js/web";
import { ErrorBoundary, Suspense } from "solid-js";
<Portal><div class="modal">Modal Content</div></Portal>
<ErrorBoundary fallback={<p>Error!</p>}><App /></ErrorBoundary>Reactivity Utilities
Advanced reactivity helpers for batching updates, untracking reads, and observing signals.
Control reactivity with batching, untracking, and explicit dependency declarations.
// Quick Reference
import { batch, untrack, on } from "solid-js";
batch(() => { setA(1); setB(2); }); // single update
const val = untrack(() => count()); // read without tracking
createEffect(on(count, (v) => console.log(v))); // explicit dep