A Brief Guide to SolidJS

A JavaScript library for building interactive user interfaces

SolidJS docs ↗

What

JSX

Mix HTML-like markup with JavaScript values.

export function Greeting(props) {
  return (
    <p>Hello, {props.name}!</p>
  )
}

Components

Build one component, then reuse it with different props.

Signals

Store changing values with a getter and setter.

Built-in APIs

<Show>
Show content conditionally.
<For>
Render a list of items.
<Loading>
Show a placeholder while data loads.
createContext
Share values across components.

Why

Less repeated work

Change state. Update only the parts of your interface that depend on it.

No virtual DOM

Change the real DOM directly, without comparing a virtual copy.

Small runtime

Keep unused framework code out of your bundle.

~7 kBMinified + gzippedSolidJS website ↗

Responsiveness

Use focused updates to help keep typing and clicks responsive.

How

Signal: a stored value with a getter, a setter, and a list of reactive computations that depend on it.

  1. Store the value

    const [mySignal, setMySignal] = createSignal(0)

    SolidJS stores the initial value and returns mySignal as the getter and setMySignal as the setter.

  2. Track the reads

    mySignal()

    When a reactive computation calls mySignal(), SolidJS records that computation as a subscriber.

  3. Notify on change

    setMySignal(1)

    If setMySignal(1) changes the value, SolidJS notifies those subscribers. Only dependent results update.