How to Use SolidJS for Reactive UI: A Practical Guide

SolidJS is a reactive UI library that delivers exceptional performance by compiling templates into real DOM nodes. Unlike Virtual DOM frameworks, SolidJS tracks fine-grained updates, ensuring only the parts of the UI that change are re-rendered. In this tutorial, you’ll learn the core concepts to build reactive interfaces with SolidJS.

First, set up a new project using solid-js. Run npx degit solidjs/templates/js my-app and then npm install. Your src/index.jsx will mount the root component. The key building blocks are signals, effects, and JSX components.

Article illustration

1. Creating Signals with createSignal

Signals are the reactive primitives. A signal holds a value and provides a getter/setter pair.

import { createSignal } from 'solid-js';
const [count, setCount] = createSignal(0);

Use count() to read the value inside any tracking scope (like JSX or effects). Call setCount(newValue) to update it. Solid automatically tracks dependencies when you call the getter inside a reactive context.

  • Always call the getter (e.g., count()) to subscribe.
  • setCount accepts a function for derived updates: setCount(c => c + 1).

2. Reactivity with createEffect

Effects run code whenever their reactive dependencies change. Use them for side effects like logging or DOM updates.

createEffect(() => {
  console.log(`Count is: ${count()}`);
});

The effect re-runs automatically when count() changes. Remember: only wrap functions that read signals inside effects or JSX to establish tracking.

3. Conditional Rendering and Loops

SolidJS uses standard JavaScript control flows inside JSX. For conditionals, use the Show component or ternary expressions. For loops, use For — it provides automatic identity management and efficient updates.

<For each={items}>{(item) => <li>{item.name}</li>}</For>

The For component tracks each array item by reference. Use a string by prop or key for stable identity.

4. Derived Computations with createMemo

When you need a value that depends on one or more signals, use createMemo. It returns a read-only signal that recomputes only when its dependencies change.

const doubleCount = createMemo(() => count() * 2);

Memos are lazy and cached. Use them like any other getter in your template.

Conclusion: SolidJS’s reactive system is both simple and powerful. By mastering signals, effects, and control flow components, you can build highly performant, real‑time UIs with minimal overhead. Start small—build a counter, then expand into more complex state management patterns.

sarah antaboga
Author: sarah antaboga

Leave a Reply

Your email address will not be published. Required fields are marked *