A component is just a function that returns some UI. You build a page by snapping components together.
<Note />.// a component is a function that returns UI (JSX)
function Welcome() {
return <h2>Hello from a component!</h2>;
}
// use it like an HTML tag:
<Welcome />
Note, not note) — that's how React tells your components apart from real HTML tags. ② It must return one thing (wrap siblings in a parent or an empty <>…</>).Small pieces combine into bigger ones. This is the whole game — an app is a tree of components:
function Note() {
return <li>Buy milk</li>;
}
function NoteList() {
return (
<ul>
<Note />
<Note />
<Note />
</ul>
);
}
function App() {
return (
<div>
<h2>My Notes</h2>
<NoteList />
</div>
);
}
Three <Note /> = three list items. Next section: how to make each note show different text (props).
<Note /> once, use it a hundred times.<Header /> <NoteList /> <Footer /> reads like a table of contents.Note lives in one small file, not tangled through the whole page.Note, not note?NoteList?<NoteList />.