Solid Components — SolidJS

A Solid component is a function with a capitalised name that returns JSX, for example function Header() { return <header><h1>Hyper Sheets</h1></header> }. A…

The page for Nadia's Bookshop is getting busy: a title at the top, book cards in the middle, a copyright line at the bottom. If it's all typed into one App function, that function soon gets long, and the same book card has to be written over and over. Components split it up. Each part becomes its own function that returns JSX, gets a name (Header, BookCard, Footer), and is assembled in one main component, App.

If you come from React, the shape is the same. The difference is when the function runs. Think of Nadia with a single book-card mould for her shop's shelves. Every time a book goes on display, the mould is used once and out comes one card. A finished card is never moulded again: when someone orders, Nadia only changes the order number on that card. The component function is the mould, <BookCard /> is one use of it, and the order number that changes is a signal inside the card.

A component is a function

function Header() {
  return (
    <header>
      <h1>Nadia's Bookshop</h1>
    </header>
  )
}

function Footer() {
  return (
    <footer>
      <p>© 2026</p>
    </footer>
  )
}

Building a page from components

function App() {
  return (
    <div>
      <Header />
      <Footer />
    </div>
  )
}

This lesson's exercise has the same shape with other content: Header renders a <header> holding <h1>Hyper Sheets</h1>, Footer renders a <footer> holding <p>© 2026</p>, and both are used inside App as <Header /> and <Footer />. The © sign can be copied from the brief, or written &copy; in JSX.

Once per use

This book card has its own signal, ordered, which goes up every time the Order button is pressed:

import { createSignal } from "solid-js"

function BookCard() {
  const [ordered, setOrdered] = createSignal(0)
  console.log("BookCard runs")

  return (
    <div class="card">
      <h2>The Rainbow Troops</h2>
      <button onClick={() => setOrdered(n => n + 1)}>Order</button>
      <p>Ordered: {ordered()}</p>
    </div>
  )
}

function App() {
  return (
    <div>
      <Header />
      <BookCard />
      <BookCard />
      <BookCard />
      <Footer />
    </div>
  )
}
Event Console What changes on the page
Page opens BookCard runs 3 times 3 cards are built
Click Order on card 2 card 2: Ordered: 0 becomes Ordered: 1
Click again card 2: Ordered: 1 becomes Ordered: 2

In total BookCard runs prints 3 times: once for each use, and it doesn't grow on clicks. So a console.log in a component body shows once per use, not on every change.

Why split into components

You could type Header's content straight into App, and the page would look exactly the same. But this exercise checks your code: <Header /> and <Footer /> must really be used in App.

⚠️ When a component doesn't show, or isn't really used

TL;DR: A Solid component is a function with a capitalised name that returns JSX, for example function Header() { return <header><h1>Hyper Sheets</h1></header> }. A component is used like a tag, <Header />, and its content is what shows on the page. A component function runs once for each use: three <BookCard /> print BookCard runs three times, then later clicks only replace the text that reads a signal. Each use has its own signals. Lowercase means an HTML tag, and without return nothing shows.

⚡ A component is a function that returns JSX

Write:

function Header() {
  return (
    <header>
      <h1>Nadia's Bookshop</h1>
    </header>
  )
}

Meaning: A component's name starts with a capital letter, and the function must return JSX. Without return, it gives back undefined and nothing shows. Lowercase, <header>, means a plain HTML tag.

⚡ Build a page from components

Write:

function App() {
  return (
    <div>
      <Header />
      <Footer />
    </div>
  )
}

Meaning: At the spot of <Header />, Solid puts whatever Header returns. The names Header and Footer never appear in the DOM, only their content does.

This exercise checks that your code really uses <Header /> and <Footer />, so don't retype their content in App.

⚡ Once per use

Guess first: App uses <BookCard /> three times, then the Order button on the second card is clicked twice. How many times does BookCard runs print?

3 times, once for each use. Clicks don't add to it: only the Ordered text on the second card changes.

Meaning: Each <BookCard /> runs the function on its own, so each card has its own ordered signal. A click on the second card doesn't change the others.

What you will learn