Mahamudul Hasan Rubel
HomeAboutProjectsSkillsExperienceBlogCoursesPhotosContact
Mahamudul Hasan Rubel

Senior Software Engineer crafting high-performance web applications and SaaS platforms.

Navigation

  • Home
  • About
  • Projects
  • Skills
  • Experience
  • Blog
  • Courses
  • Photos
  • Contact

Get in Touch

Available for senior/lead roles and consulting.

bd.mhrubel@gmail.comHire Me

© 2026 Mahamudul Hasan Rubel. All rights reserved.

Built with using Next.js 16 & Tailwind v4

Back to Blog
Lesson 9 of the React Fundamentals: Build Modern UIs from Scratch course
ReactJune 25, 20263 min read

Mastering Component Composition: Organize Your React UI Hierarchy

Stop building monolithic files. Learn how to combine small, reusable components into a clean, scalable UI hierarchy using React composition techniques.

ReactComponent CompositionUI DesignFrontend DevelopmentWeb Developmentjavascriptfrontend

Previously in this course, we covered Passing Data with Props and built Dynamic Movie Cards. By now, you know how to create individual building blocks. But a professional application isn't just a pile of isolated cards; it's a structured tree of nested components.

In this lesson, we’ll move from building single components to mastering component composition. This is the art of combining small, focused components into a larger, logical structure.

Why UI Hierarchy Matters

If you keep every piece of your UI in one file, you end up with "spaghetti code"—a massive, unreadable component that is impossible to debug. By using nested components, you break the UI into a tree-like hierarchy.

Think of our movie-browser app. Instead of one giant App component, we want a structure that looks like this:

  • App (The root container)
    • Header (Navigation and branding)
    • Main (Layout wrapper)
      • MovieList (Container for all cards)
        • MovieCard (The individual display)
    • Footer (Copyright and links)

This isn't just about tidiness. It’s about separation of concerns. Each parent component manages the "where" and "how" of its children, while the children focus strictly on their own rendering.

Worked Example: Building the Layout

Let’s evolve our project by creating a Layout component that encapsulates our header and footer, allowing the App component to focus purely on the content.

First, let's create a Header.jsx component:

JSX
// components/Header.jsx
export function Header() {
  return (
    <header className="site-header">
      <h1>MovieBrowser Pro</h1>
    </header>
  );
}

Now, instead of manually adding the header and footer to every page, we use a parent Layout component. This component will accept children—a special prop in React that allows you to pass components inside another component.

JSX
// components/Layout.jsx
import { Header } from CE9178">'./Header';

export function Layout({ children }) {
  return (
    <div className="app-container">
      <Header />
      <main className="content">
        {children}
      </main>
      <footer>© 2023 MovieBrowser Inc.</footer>
    </div>
  );
}

Now, inside App.jsx, we can wrap our content with this Layout:

JSX
// App.jsx
import { Layout } from CE9178">'./components/Layout';
import { MovieCard } from CE9178">'./components/MovieCard';

export default function App() {
  return (
    <Layout>
      <div className="movie-grid">
        <MovieCard title="Inception" />
        <MovieCard title="Interstellar" />
      </div>
    </Layout>
  );
}

Notice how App is now much cleaner. It doesn't need to know how the Header is built; it only knows that the Layout provides the structure. This is the core of React composition patterns.

Hands-on Exercise

To practice this, take your current movie-browser project and perform these three steps:

  1. Create a new Sidebar component.
  2. Update your Layout component to include the Sidebar next to the main tag.
  3. Move your MovieList into the main section of the Layout.

Verify that your styles still apply correctly. If the sidebar appears on the left and the movies on the right, you've successfully managed your first complex UI tree!

Common Pitfalls

  • Over-nesting: Don't create a new component for every single <div>. If a piece of UI is only used once and isn't complex, it might be better off staying inside its parent.
  • Ignoring the children prop: Beginners often try to pass components as custom props (like header={<Header />}). While this works, using the children prop is the standard way to compose layouts in React, as discussed in React composition and the children prop for scalable UI libraries.
  • Prop Drilling: If you find yourself passing props through three or four levels of components just to reach the bottom, stop. We will address how to solve this with state management later in the course, but for now, keep your hierarchy shallow where possible.

Recap

Composition allows us to build complex interfaces by nesting simple, reusable pieces. By utilizing the children prop and organizing our components into a logical tree, we create a codebase that is easier to navigate, test, and maintain.

Up next: We'll explore Conditional Rendering to hide or show parts of our UI based on user interaction.

Previous lessonDynamic Movie CardsNext lesson Conditional Rendering
Back to Blog

Similar Posts

ReactReactJune 25, 20263 min read

Fetching Data from an API: A Practical React Guide

Master the fetch API in React to retrieve external data. Learn to perform asynchronous requests and store JSON responses in your component state effectively.

Read more
ReactReactJune 25, 20263 min read

Part of the course

React Fundamentals: Build Modern UIs from Scratch

beginner · Lesson 9 of 49

  1. 1

    Introduction to Component-Based Architecture

    4 min
  2. 2

    Understanding the Virtual DOM

    4 min
  3. 3

    Setting Up with Vite

    3 min

Building a Movie Filter Toggle in React: A Beginner's Guide

Master the art of UI state management by adding a filter toggle to your movie app. Learn to control list rendering using boolean state and checkbox inputs.

Read more
ReactReactJune 25, 20264 min read

Rendering Lists of Data in React: A Practical Guide

Learn how to use the map method for list rendering in React. Master the key prop to keep your dynamic movie lists efficient, performant, and bug-free.

Read more
4

Mastering JSX Syntax

4 min
  • 5

    Creating Static Components

    3 min
  • 6

    Styling Components

    3 min
  • 7

    Passing Data with Props

    3 min
  • 8

    Dynamic Movie Cards

    3 min
  • 9

    Component Composition

    3 min
  • 10

    Conditional Rendering

    3 min
  • 11

    Rendering Lists of Data

    4 min
  • 12

    The Key Prop Explained

    4 min
  • 13

    Introduction to React State

    4 min
  • 14

    Managing State with useState

    3 min
  • 15

    Building an Interactive Search Bar

    3 min
  • 16

    Handling Click Events

    4 min
  • 17

    Updating State Based on Previous State

    4 min
  • 18

    Filtering the Movie List

    3 min
  • 19

    Handling Form Submissions

    3 min
  • 20

    Controlled Components

    4 min
  • 21

    Event Bubbling and Propagation

    3 min
  • 22

    Building a Movie Filter Toggle

    3 min
  • 23

    Introduction to Side Effects

    4 min
  • 24

    useEffect Dependencies

    4 min
  • 25

    Fetching Data from an API

    3 min
  • 26

    Handling Loading States

    3 min
  • 27

    Managing Errors

    3 min
  • 28

    Cleanup Functions in useEffect

    3 min
  • 29

    Debouncing Search Input

    3 min
  • 30

    Refactoring for Clean Code

    3 min
  • 31

    Folder Structure Best Practices

    4 min
  • 32

    Extracting Custom Hooks

    3 min
  • 33

    Prop Drilling and Context API

    3 min
  • 34

    Polishing the UI

    Coming soon
  • 35

    Finalizing the Movie Browser

    Coming soon
  • 36

    Review of Component Lifecycle

    Coming soon
  • 37

    Review of State Management

    Coming soon
  • 38

    Building a Modal Component

    Coming soon
  • 39

    Introduction to PropTypes

    Coming soon
  • 40

    Performance Optimization Basics

    Coming soon
  • 41

    Handling Browser History

    Coming soon
  • 42

    Working with LocalStorage

    Coming soon
  • 43

    Building a Favorites List

    Coming soon
  • 44

    Handling Media in React

    Coming soon
  • 45

    Introduction to Testing

    Coming soon
  • 46

    Debugging React Apps

    Coming soon
  • 47

    Deployment Basics

    Coming soon
  • 48

    Using External Libraries

    Coming soon
  • 49

    Advanced

    Coming soon
  • View full course