A Brief Guide to SolidJS

Code Examples

SolidJS docs ↗

Implementation of a simple Counter.

Both counters: 0

SolidJS

Current count: 0

import { createSignal } from 'solid-js'

function Counter() {
  const [count, setCount] = createSignal(0)

  return (
    <section>
      <button onClick={() => setCount((n) => n + 1)}>
        Click to increment Counter
      </button>
      <p>Current count: <span>{count()}</span></p>
    </section>
  )
}

Both count() bindings update directly. SolidJS does not call Counter() again.

React

import { useState } from 'react'

function Counter() {
  const [count, setCount] = useState(0)

  return (
    <section>
      <button onClick={() => setCount((n) => n + 1)}>
        Click to increment Counter
      </button>
      <p>Current count: <span>{count}</span></p>
    </section>
  )
}

React calls Counter() again and compares the result.