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>
)
}
- A component is defined as a plain function. An arrow function works too:
const Footer = () => <footer>...</footer>. - The function must
returnJSX. Withoutreturn, it gives backundefinedand nothing shows. - Its name starts with a capital letter.
<Header />means "use the Header component", while lowercase<header>is a plain HTML tag. - The
<header>and<footer>inside are semantic HTML tags for the top and bottom of the page.
Building a page from components
function App() {
return (
<div>
<Header />
<Footer />
</div>
)
}
<Header />is written like a self-closing tag. At that spot, Solid puts whateverHeaderreturns.- The result on the page:
<div><header><h1>Nadia's Bookshop</h1></header><footer><p>© 2026</p></footer></div>. The namesHeaderandFooternever appear in the DOM, only their content does. - The Solid 1.9 compiler writes each use as
_$createComponent(Header, {}): call theHeaderfunction once, then insert its result.
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 © 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.
- Each
<BookCard />runs the function on its own, so each card has its ownorderedsignal. A click on the second card doesn't change the first or the third. - All three cards are identical (
The Rainbow Troops), becauseBookCardcan't take data from outside yet. That's what props are for, in the next lesson.
Why split into components
- Reuse. One
BookCardfunction, however many cards. - Easy to read.
Appholds<Header />,<BookCard />,<Footer />, like the page's table of contents. - Change in one place. Edit
Footeronce, and every page that uses it changes too.
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
- A lowercase component name.
function header()then<header />doesn't call your function: Solid treats it as an empty HTML<header>tag. Start component names with a capital letter. - Forgetting
return.function Footer() { <footer>...</footer> }gives backundefined, so the footer never shows. - Expecting a component's
console.logto run on every click. It runs once per use. What runs on a click is only the part that reads a signal, such as{ordered()}. - Typing a component's content straight into
App. It looks the same, but there's no component to reuse, and the exercise fails on its<Header />and<Footer />checks.
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.