Section 2 · Components

UI made of LEGO bricks

A component is just a function that returns some UI. You build a page by snapping components together.

🎯 In one line: a component is a function whose name starts with a Capital letter and returns JSX — reusable UI you can drop in anywhere like <Note />.

1Your first component

// 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 />
Two rules ① A component's name is Capitalised (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 <>…</>).

2Components use components

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>
  );
}

👀 What that renders

My Notes

  • Buy milk
  • Buy milk
  • Buy milk

Three <Note /> = three list items. Next section: how to make each note show different text (props).

3Why split into components?

🧠

Quick check

1. A React component is…
Components are functions returning JSX — reusable pieces of interface.
2. Why must a component be named Note, not note?
Capitalised = your component; lowercase = a built-in HTML element. React uses the case to decide.
3. How do you use a component called NoteList?
You use components as if they were HTML tags: <NoteList />.
🔓 You're reading a free chapter of React — the first two are open.
Unlock the rest of this course with a one-time payment.
Unlock this course →
🔓 See course prices