SolidJS

1.9.12 · active · verified Sun Apr 19

SolidJS is a declarative JavaScript library for building user interfaces, currently stable at version 1.9.12, with a 2.0 beta release recently announced. It distinguishes itself from other UI libraries by compiling JSX templates directly to real DOM operations and fine-grained reactive primitives, avoiding a virtual DOM. This approach typically leads to excellent performance characteristics and a smaller bundle size. Solid focuses on explicit reactivity through signals, memos, and effects, providing granular control over updates without component re-renders. The project maintains a regular release cadence, primarily focusing on quality-of-life improvements and performance optimizations within the 1.x line, while actively developing the significant architectural changes and API re-evaluations slated for the upcoming 2.0 release.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates a basic SolidJS component using `createSignal` for state, `createEffect` for side effects, and `render` to mount the application to the DOM. It shows a simple interactive counter.

import { createSignal, createEffect, onCleanup } from 'solid-js';
import { render } from 'solid-js/web';

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

  createEffect(() => {
    console.log(`Current count: ${count()}`);
    // Example of cleanup logic for an effect
    onCleanup(() => console.log('Cleaning up effect for count change.'));
  });

  return (
    <div>
      <h1>SolidJS Counter</h1>
      <p>Count: {count()}</p>
      <button onClick={() => setCount(c => c + 1)}>Increment</button>
      <button onClick={() => setCount(c => c - 1)}>Decrement</button>
    </div>
  );
}

const appRoot = document.getElementById('app');
if (appRoot) {
  render(() => <Counter />, appRoot);
} else {
  console.error("Element with id 'app' not found.");
}

view raw JSON →