#1 India's Top IT Training Institute
×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
Mentors

Mentors

Meet the industry experts who train and guide you through your course.

Read More →
Free Resources

Free Resources

Free tutorials, interview questions, tools and calculators to help you learn.

Explore →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →
Components

Why Components?

Components are self-contained pieces of user interface, such as a button, a product card or a whole navigation bar, that you write once and combine to build pages. React is built entirely around them. Instead of one giant HTML file with scattered scripts, you describe each part of the screen as a function that returns JSX and owns its own logic. This lesson explains why that approach makes apps easier to build and change.

Reuse without copy and paste

Look at any shopping site and you will see the same card repeated dozens of times with different data. Without components, you would copy the markup for each card and update every copy when the design changes. With a component, the structure lives in one place and data is passed in through props.

function ProductCard({ name, price, imageUrl }) {
  return (
    <article className="product-card">
      <img src={imageUrl} alt={name} />
      <h3>{name}</h3>
      <p>₹{price}</p>
      <button>Add to cart</button>
    </article>
  );
}

function ProductList({ products }) {
  return (
    <section>
      {products.map((p) => (
        <ProductCard key={p.id} name={p.name} price={p.price} imageUrl={p.image} />
      ))}
    </section>
  );
}

Change ProductCard once, and every card on every page updates.

Each piece keeps its own logic

In traditional pages, HTML, CSS and JavaScript are split into separate files by technology. A single feature, like a dropdown, ends up spread across all three. React groups code by feature instead. A SearchBox component holds its markup, its state for the typed text and its event handlers together. When something breaks in the search box, you know exactly where to look.

This isolation also prevents accidental interference. Two components can both have a variable called isOpen without clashing, because each one keeps its own state.

Building big screens from small parts

Components nest inside each other, which is called composition. A Page contains a Header, a Sidebar and a Feed; the Feed contains many Post components; each Post contains a LikeButton. You end up with a tree that mirrors how you think about the screen.

This structure brings practical benefits:

  • Teamwork: different people can work on different components at the same time.
  • Testing: a small component with clear inputs is easy to test on its own.
  • Readability: <Header /> tells you what it is far faster than fifty lines of markup.
  • Libraries: entire design systems and UI kits are shared as ready-made components.

Getting the size of a component right

A common beginner mistake is the opposite of the old problem: either one huge App component that does everything, or splitting so aggressively that every <span> becomes its own file. A useful rule is to extract a component when a piece of UI repeats, when it has its own state or behaviour, or when the parent has grown hard to read. If you have to scroll a lot to understand a component, it is probably doing too much.

Another early stumble is naming. React treats lowercase tags such as <card /> as plain HTML elements. Component names must start with a capital letter, like <Card />, or React will not call your function.

What to take away

Components give you reuse, keep related code together, and let you assemble complex screens from simple, understandable parts. Think of each one as a custom HTML tag you design yourself. In the next lesson you will start writing JSX inside components to describe what they render.

Ready to master real-world web development?

Learn HTML, CSS3, Bootstrap and JavaScript hands-on with mentor-led sessions.

Explore Course