LearnContact
Lesson 1120 min read

Components

Learn what a component is, how components are named and composed together, and the two ways React lets you write them.

Introduction

You have already seen JSX and React elements — the building blocks React uses to describe what should appear on screen. But writing raw elements for an entire application would be repetitive and hard to manage. React solves this with components: the single most important concept in the entire library.

Almost everything you build in React — a button, a navbar, a whole page — is a component. This lesson introduces what a component actually is, how components combine to build bigger UIs, the rules around naming them, and the two syntaxes React supports for writing them.

What You Will Learn
  • What a component is and why it matters.
  • How components are composed by nesting them inside each other.
  • The naming rule every component must follow.
  • The difference between function and class components (a preview of the next two lessons).

What is a Component?

A component is an independent, reusable piece of UI. Think of it like a custom HTML element you define yourself — instead of being limited to <div>, <button>, or <p>, you can create your own building blocks like <Navbar />, <ProductCard />, or <LoginForm />, each bundling up its own markup and logic.

Once you define a component, you can use it as many times as you like, anywhere in your application, just by referencing its name in JSX. Each usage is called an "instance" of that component, and each instance can display different data.

Independent

A component manages its own markup and logic without depending on the rest of the page.

Reusable

Write it once, then reuse it anywhere you need that piece of UI.

Custom Element

It behaves like a custom HTML tag that you invented for your app.

Self-Contained

Everything the component needs to render usually lives inside it.

A Simple Component
function Welcome() {
  return <h1>Hello, welcome to PrograMinds!</h1>;
}

// Using the component like a custom HTML tag
function App() {
  return (
    <div>
      <Welcome />
    </div>
  );
}
Rendered on the Page
Hello, welcome to PrograMinds!

Composing Components

Composing components simply means nesting them inside one another to build bigger pieces of UI from smaller ones — exactly the way HTML tags nest inside each other. A Page component might render a Header, a list of Card components, and a Footer, each of which might contain even smaller components.

Composing Smaller Components Into a Page
function Header() {
  return <h1>My Store</h1>;
}

function ProductCard({ name }) {
  return <div className="card">{name}</div>;
}

function Footer() {
  return <p>© 2026 My Store</p>;
}

function Page() {
  return (
    <div>
      <Header />
      <ProductCard name="Keyboard" />
      <ProductCard name="Mouse" />
      <Footer />
    </div>
  );
}
Rendered on the Page
My Store
Keyboard
Mouse
© 2026 My Store
Think in Trees

A composed set of components forms a tree, with one top-level component (often called App) at the root and smaller components as its branches and leaves. This is called the "component tree."

Component Naming Rules

React uses a simple but strict rule to tell components apart from regular HTML tags: component names must start with a capital letter. Lowercase names like <div> or <button> are treated as built-in HTML tags, while capitalized names like <Welcome /> or <ProductCard /> are treated as your own components.

Valid Component Names

  • function Welcome() { ... }
  • function ProductCard() { ... }
  • function NavBar() { ... }

Invalid Component Names

  • function welcome() { ... } // lowercase — React treats <welcome /> as an unknown HTML tag
  • function product_card() { ... } // lowercase — same problem
Why Capitalization Matters

If you write <welcome /> with a lowercase name, React assumes you mean an HTML element called "welcome" — which does not exist — instead of your component. This is not just a style preference; it changes how React interprets your JSX.

Two Ways to Write Components

React has always supported two syntaxes for defining a component: function components and class components. Both ultimately do the same job — accept some input and return JSX describing the UI — but they look and behave quite differently.

Function Components

A plain JavaScript function that returns JSX. This is the modern standard, especially when paired with Hooks. Covered in depth in the next lesson.

Class Components

An older, class-based syntax using this.props and this.state. Still found in legacy codebases. Covered in the lesson after next.

The Same Component, Two Syntaxes
// Function component (modern standard)
function Greeting({ name }) {
  return <h1>Hello, {name}!</h1>;
}

// Class component (legacy, still seen in older code)
class Greeting extends React.Component {
  render() {
    return <h1>Hello, {this.props.name}!</h1>;
  }
}

You will rarely need to write a brand-new class component in modern React code, but you will still encounter them when reading older projects, tutorials, or libraries — which is exactly why the next two lessons cover both in detail.

Example: A Small Component Tree

Here is a slightly larger example showing composition in action: a top-level App component made entirely out of smaller, named components.

App.jsx
function Avatar() {
  return <img src="/avatar.png" alt="User avatar" />;
}

function UserInfo() {
  return (
    <div>
      <Avatar />
      <p>Amol Chipte</p>
    </div>
  );
}

function App() {
  return (
    <div>
      <h1>Dashboard</h1>
      <UserInfo />
    </div>
  );
}

export default App;
Rendered on the Page
Dashboard
[avatar image]
Amol Chipte

Common Mistakes

Avoid These Mistakes
  • Naming a component starting with a lowercase letter, causing React to treat it as an unknown HTML tag.
  • Defining a component inside another component's function body, which recreates it on every render and can cause bugs.
  • Forgetting that a component must return a single root element (or a Fragment) — returning multiple sibling elements directly is not allowed.
  • Confusing a component definition (the function or class) with a component instance (its usage in JSX, like <Welcome />).

Best Practices

  • Give every component a clear, capitalized, descriptive name that reflects what it renders.
  • Keep components small and focused on a single piece of UI or responsibility.
  • Define components at the top level of a file, not nested inside other components.
  • Favor composition — building bigger components out of smaller ones — over one giant component.
  • Default to function components for any new code you write.

Frequently Asked Questions

Is a component the same thing as a React element?

No. A component is the function or class definition — the blueprint. An element (like the object <Welcome /> compiles into) is what you get when that component is used. A component can produce many elements, one for each place it is used.

Can a component name have numbers or lowercase letters in it?

Yes, as long as the very first character is an uppercase letter. Names like Card2 or UserProfile are fine.

Do I have to choose one style — function or class — for my whole app?

No, React lets function and class components coexist in the same application, and they can even render each other. Most modern codebases use function components almost exclusively, though.

Can a component return more than one top-level element?

Not directly — a component must return a single root node. If you need multiple sibling elements, wrap them in a <div> or a Fragment (<>...</>) instead.

Why does React care so much about naming conventions?

Because JSX compiles to plain JavaScript function calls, React needs a simple rule to tell "your component" apart from "a built-in HTML tag" at a glance, and capitalization is that rule.

Key Takeaways

  • A component is an independent, reusable piece of UI, like a custom HTML element you define yourself.
  • Components are composed by nesting them inside one another, forming a component tree.
  • Component names must start with a capital letter, or React will treat them as unknown HTML tags.
  • React supports two syntaxes for components: functions (the modern standard) and classes (legacy).
  • The next two lessons dive deep into function components and class components respectively.

Summary

Components are the core unit of React development: independent, reusable, nameable pieces of UI that compose together into full applications. Getting comfortable with the idea of building UIs out of small, named building blocks is the biggest mental shift when learning React.

In this lesson, you learned what a component is, how composition works, the capitalization naming rule, and that components can be written as functions or classes. Next, you will go deep on function components — the modern standard for writing React UIs.

Lesson 11 Completed
  • You understand what a component is and why it matters.
  • You can compose smaller components into larger ones.
  • You know the capitalization rule for naming components.
  • You are ready to explore function components in depth.
Next Lesson →

Functional Components