Nadia's Bookshop, a small shop, has a stock board. Every time a book sells, its stock number has to change, and there are two ways to do it. The first way: Nadia rewrites the whole board on a new sheet, compares it with the old board line by line, then copies the numbers that are different. The second way: each number is written on a small card that hangs on the board, and each card is linked to the stock of one book. When that book sells, only its card is replaced. The board itself is not touched.
SolidJS updates a web page the second way. In this picture, the board is the web page, the stock numbers are the data, and each card is a small piece of the page that shows one piece of data. SolidJS (or Solid) is a JavaScript library, a set of ready-made code, for building web interfaces. An interface is built from components (parts of the interface, each written as a function). What a component shows is written in JSX, as in React (the most popular library for web interfaces today). React is closer to the first way: every time data changes, React calls the component function again. In Solid, a component function runs only once. When data changes, Solid directly replaces only the piece of the page that uses that data.
Your first component
A Solid component is a plain function that returns JSX. JSX is a way of writing HTML-like tags directly inside JavaScript. The simplest component:
function App() {
return <h1>Hello Solid!</h1>
}
function App()is the component. Its name starts with a capital letter.return <h1>Hello Solid!</h1>returns one heading that holdsHello Solid!. This is also the answer to this lesson's exercise: the code is already in the editor, you only run it.
In a real project, the render function puts the App component on the page, once:
import { render } from "solid-js/web"
render(() => <App />, document.getElementById("root"))
In the exercise editor, this step is done for you: the editor looks for the App component and puts it on the page.
In this track we build a small page for Nadia's Bookshop: a list of books (The Rainbow Troops, This Earth of Mankind, Beauty Is a Wound), their stock, and a shopping cart. Each lesson adds one piece.
A component runs once
This is the cart button of Nadia's Bookshop. The number of books in the cart is kept in a signal: Solid's container for a value, which tells the page when the value changes (covered fully in the Signals lesson). createSignal(0) creates a signal that holds 0 and gives you two functions: count() reads the value, and setCount changes it:
import { createSignal } from "solid-js"
function App() {
const [count, setCount] = createSignal(0)
console.log("App runs")
return (
<div>
<button onClick={() => setCount(c => c + 1)}>+1 Book</button>
<p>Cart: {count()} books</p>
</div>
)
}
This table records what happens when the page opens and the button is clicked three times:
| Event | Is App called? |
Console | What changes on the page |
|---|---|---|---|
| Page opens | yes, once | App runs |
div, button, p are built |
| Click 1 | no | text 0 becomes 1 |
|
| Click 2 | no | text 1 becomes 2 |
|
| Click 3 | no | text 2 becomes 3 |
App runs is printed once. The App function only sets things up: it creates the signal, builds the elements, and sets up the link "this text follows count". After that App is finished and is never called again. On each click, Solid directly replaces one piece of text, the number.
In React, the same component prints App runs 4 times: once when the page opens, then once for each click. The reason: React calls the component function again every time state (the data a component keeps) changes. Each of those calls is a re-render. The 4 is without <StrictMode>. Vite's React template turns on <StrictMode>, and in development React calls the component function twice per render, so App runs prints even more often.
No virtual DOM
The DOM is the tree of page elements that the browser holds. React does not change the DOM directly from your code. On each re-render, React does three steps:
- It builds a new picture of the interface, made of JavaScript objects. This picture is called the virtual DOM.
- It compares the new picture with the old one.
- It changes the parts of the DOM that are different.
Solid has no virtual DOM. Solid's compiler (a program that translates code before it reaches the browser) turns your JSX into plain JavaScript that builds real DOM elements. This is part of what the Solid 1.9 compiler (babel-preset-solid) produces for the cart button above:
var _tmpl$ = _$template(`<div><button>+1 Book</button><p>Cart: <!> books`)
function App() {
const [count, setCount] = createSignal(0)
console.log("App runs")
return (() => {
var _el$ = _tmpl$()
// ... _el$2 is the <button>, _el$3 the <p>, _el$6 marks where the number goes
_el$2.$$click = () => setCount(c => c + 1)
_$insert(_el$3, count, _el$6)
return _el$
})()
}
_$template(...)keeps the HTML that never changes as one string._tmpl$()copies that string into real DOM elements in one step._$insert(_el$3, count, _el$6)sets up the link: the marked spot inside the paragraph is filled fromcount. Every timecountchanges, only the text at that spot is replaced.- Nothing is compared, because Solid has already recorded which text depends on
count.
This way of working is called fine-grained reactivity. Reactivity means the page follows the data automatically. Fine-grained means that what changes is the smallest piece, one text or one attribute, not a whole component.
Solid and React side by side
Solid and React compared, for the same cart button:
| Solid 1.9 | React 19 | |
|---|---|---|
| Keeping data | createSignal(0) |
useState(0) |
| Reading the value | count(), called like a function |
count |
| Component function is called | once | on every re-render |
| When data changes | replace the linked text | re-render, compare virtual DOMs, change what differs |
| Size of the cart button above (minify + gzip) | 5.0 KB | 60.5 KB |
The end result on the page is the same: both replace only one text. The difference is in the work before that text is replaced. The last row is the size of the code sent to the browser. The code was bundled (joined into one file) with esbuild, minified (made smaller), then compressed with gzip. If you have learned React before, its ideas (components, props, state) also apply in Solid. Only how you use them differs a little.
Start your own project
On your computer, you create a Solid project from an official template (an example project ready to copy). Type these commands in a terminal (the window for typing commands):
npm create vite@latest bookshop -- --template solid
cd bookshop
npm install
npm run dev
npm create vite@latest bookshop -- --template solidcopies Vite's official Solid template (JavaScript, Solid 1.9) into thebookshopfolder. For TypeScript, replacesolidwithsolid-ts. The old commandnpx degit solidjs/templates/jsno longer works, because thejsfolder was removed from Solid's template repository in September 2025.cd bookshopgoes into that folder, andnpm installdownloads the libraries the project needs.npm run devstarts the Vite dev server: a program that compiles your JSX every time you save a file.- Another way:
npm create solid@latest. This command asks a few questions, including whether your project uses SolidStart. SolidStart is a framework (a larger toolkit) on top of Solid for routing (moving between pages) and servers, covered at the end of this track. - This track teaches Solid 1.9, the latest stable version (
solid-js1.9.19). So if you usenpm create solid@latest, pick SolidJS + Vite (Solid 1.x) when it asks for the project type. The option Solid 2.0 (RC) is still a release candidate, and some names differ there:<Suspense>becomes<Loading>,onMountbecomesonSettled, andcreateResourceis removed.
The exercise editor here does not use Solid's real compiler. It runs your JSX with a small model of Solid that has the same signals and links. For the basics, the result is the same. Where it differs, the lesson says so.
⚠️ What confuses people on day one
- Writing
countwithout parentheses. A signal is read by calling it:count(). The React habit ({count}) only appears as a mistake when you calculate with the value, for example{count * 18}showsNaN(not a number), because the function is multiplied, not its value. - Expecting
console.login the component body to run on every update. Thatconsole.logruns only once. For code that runs every time data changes, seecreateEffectin the Effects lesson. - Opening a
.jsxfile directly in the browser. Browsers do not understand JSX. The file has to be compiled first, bynpm run dev. - Bringing every React habit along. Solid uses
class, notclassName, and props should not be destructured.classis covered in the lesson JSX in Solid, and props in the lesson Solid Props.
TL;DR: SolidJS is a JavaScript library for building web interfaces from components: functions that return JSX (HTML-like tags inside JavaScript). Solid uses JSX like React, but without a virtual DOM (a picture of the interface that React rebuilds and compares on every change). A Solid component function runs only once, to set up the elements and their links to signals (values that tell the page when they change). So a console.log inside a component prints once even when a button that changes a signal is clicked three times (in React: four times). When data changes, Solid directly replaces only the linked text. That is called fine-grained reactivity. A signal is read with parentheses, for example a signal named count is read with count(). The simplest component: function App() { return <h1>Hello Solid!</h1> }. A new project starts with npm create vite@latest bookshop -- --template solid or npm create solid@latest.
⚡ A component is a function
Write:
function App() {
return <h1>Hello Solid!</h1>
}
Meaning: Solid is a JavaScript library for building web interfaces from components. A Solid component (a part of the interface) is a plain function that returns JSX (HTML-like tags inside JavaScript), and its name starts with a capital letter. In a real project, the render function puts App on the page, once. In the exercise editor, that step is done for you.
⚡ A component runs only once
Write:
function App() {
const [count, setCount] = createSignal(0)
console.log("App runs")
return <button onClick={() => setCount(c => c + 1)}>+1 Book</button>
}
Guess first: createSignal(0) creates a signal, Solid's container for a value, and each click adds 1 to the value. The button is clicked three times. How many times is App runs printed?
Once. The App function runs only when the page opens, to set up the elements and their links to the signal. Each click changes the signal's value, but App is not called again. If a part of the page reads that signal, Solid replaces only that part. In React, the same component prints 4 times.
Meaning: Solid does not use a virtual DOM, a picture of the interface that React rebuilds and compares on every change. Solid records which text follows which signal, then replaces only that text. This is called fine-grained reactivity. A signal is read by calling its reader function, count(), and changed with setCount.
⚡ Start a project from the official template
Write:
npm create vite@latest bookshop -- --template solid
cd bookshop
npm install
npm run dev
Meaning: In a terminal, npm create vite@latest with --template solid copies Vite's official Solid template (an example project), the JavaScript version, into a new folder. cd goes into that folder, and npm install downloads the libraries it needs. npm run dev starts the Vite server, which compiles your JSX into plain JavaScript for the browser. Another way: npm create solid@latest.