Components
โš›๏ธ React 18+ ๐ŸŸข Chapter 7 of 39 ๐Ÿ“‚ Phase 03: JSX and UI ๐Ÿ“… 2026 Edition
๐Ÿ“Œ Covered in this chapter: Component Definition ยท Naming Rules ยท Reusable Components ยท Nesting ยท Parent/Child ยท Folder Structure ยท Presentational vs Container
With JSX and styling covered, this chapter focuses on component design itself โ€” how to structure, name, nest, and organize components as your app grows beyond a single file.
1Composing Components by Nesting

Components can render other components inside them, building up a full UI from small, focused pieces โ€” exactly matching the component tree from Chapter 1:

function Header() {
  return <header><h1>My Site</h1></header>;
}

function Footer() {
  return <footer>ยฉ 2026</footer>;
}

function App() {
  return (
    <>
      <Header />
      <main>Page content here</main>
      <Footer />
    </>
  );
}
2Recommended Project Folder Structure
src/ โ”œโ”€โ”€ components/ โ”‚ โ”œโ”€โ”€ Header.jsx โ”‚ โ”œโ”€โ”€ Button.jsx โ”‚ โ””โ”€โ”€ Card.jsx โ”œโ”€โ”€ App.jsx โ””โ”€โ”€ main.jsx

As a project grows past a handful of components, keeping them all in a dedicated components/ folder (rather than scattered in src/ directly) keeps the project navigable โ€” this is the near-universal convention in real React codebases.

3Presentational vs Container Components

A useful mental split as apps grow: presentational components just receive data and render UI (like a Card that displays a title and image), while container components manage data, state, and logic, then pass the results down to presentational children. This isn't a strict rule enforced by React itself, but it's a widely used pattern for keeping components focused and reusable โ€” you'll build on this idea directly in Chapter 28 (Component Design).

โš ๏ธ Splitting Components Too Early or Too Late

Breaking every single element into its own tiny component creates excessive complexity and prop-passing overhead. Cramming an entire page into one giant component makes it unreadable and hard to reuse. A good rule of thumb: if a piece of UI is reused, or if a section is complex enough to reason about on its own, it deserves its own component.

๐Ÿ’ป Hands-on Interactive Practice Challenge

Build a small ProfileCard component that renders a name, a bio, and is used twice inside App.jsx with different content.

React Practice Challenge โ–ถ Run in Compiler
function ProfileCard() {
  return (
    <div className="card">
      <h3>Priya Sharma</h3>
      <p>Frontend Developer learning React.</p>
    </div>
  );
}

function App() {
  return (
    <>
      <ProfileCard />
      <ProfileCard />
    </>
  );
}
Run This Challenge in Online JS IDE โ†’
โ“ Frequently Asked Questions (FAQ)

Q How do I decide when to create a new component?

A good signal is reuse โ€” if the same UI pattern appears more than once, extract it. Another signal is complexity โ€” if a section of JSX is getting long or handles its own distinct logic, splitting it out improves readability.

Q Can a component file contain more than one component?

Yes, technically, but the convention is one main component per file, matching the filename. Small helper components used only within that file are a reasonable exception.

OC
Written by Our Compiler Technical Editorial Team
Reviewed for accuracy & tested on React 18+ ยท Last updated August 2026