React BasicsCore· 40 min read

Components

Build your own reusable UI pieces — and compose them like LEGO bricks.

What you will learn

  • Create function components
  • Use one component inside another
  • Follow the naming rules

A component is a function that returns JSX

Define a component as a function whose name starts with a capital letter. It returns JSX. Then use it like an HTML tag: <MyComponent />.

Define a component, then use it
function Welcome() {
  return <h2>Welcome to CodingClave!</h2>;
}

function App() {
  return (
    <div>
      <Welcome />
      <p>The heading above comes from the Welcome component.</p>
    </div>
  );
}
Live preview

Two functions here. Welcome is a small component that returns one heading. App is the main component, and inside its markup it uses <Welcome /> — exactly like an HTML tag. When React draws App, it sees <Welcome /> and swaps in whatever Welcome returns. This is composition: building a bigger UI by placing smaller components inside it.

Note: Output: Welcome to CodingClave! The heading above comes from the Welcome component. The first line came from the Welcome component; the second from App itself.

Compose and reuse

One Card component, used three times
function Card() {
  return (
    <div style={{ border: "1px solid #ccc", borderRadius: 10, padding: 12, margin: 6 }}>
      <h4>A reusable card</h4>
      <p>Used as many times as you like.</p>
    </div>
  );
}

function App() {
  return (
    <div>
      <Card />
      <Card />
      <Card />
    </div>
  );
}
Live preview

We wrote the Card component once (a bordered box with a heading and text), then used <Card /> three times inside App. React renders three identical cards. Change the Card definition in one place and all three update together — that is the power of reusable components. (The style={{ ... }} is an inline style object; styling is covered in its own lesson.)

Note: Output: Three identical bordered cards stacked down the page, each showing A reusable card and “Used as many times as you like.”

Watch out: Component names must start with a capital letter (Card, not card). React treats lowercase names as ordinary HTML tags.

Tip: Each component usually lives in its own file (Card.jsx) and is exported, then imported where needed. This keeps big apps organised.

Q. What must a React component name start with?

Answer: Component names must start with a capital letter so React treats them as components, not plain HTML tags.

✍️ Practice

  1. Create a Header component and use it in App.
  2. Create a Card component and render it three times.

🏠 Homework

  1. Build a small page from three components: Header, Content and Footer.
Want to learn this with a mentor?

CodingClave runs guided, project-based training (28-day, 45-day & 6-month batches).

Explore Training →