Component Tree in React
Understand parent-child relationships, component hierarchy and how React components form a tree at CIIT Training Institute.
01 Learning Objectives
After completing this lesson, you will be able to:
Learn how components form a hierarchy.
Understand how one component renders another.
Follow component relationships in JSX.
Break a page into manageable components.
02 What Is a Component Tree?
A component tree is a hierarchical representation of how React components are nested inside one another. The root component sits at the top, and the components it renders appear as children.
App renders Header and
CourseList, those components are children of
App in the component tree.
function Header() {
return <h2>CIIT Training Institute</h2>;
}
function CourseList() {
return (
<ul>
<li>React JS</li>
<li>.NET Full Stack</li>
</ul>
);
}
function App() {
return (
<div>
<Header />
<CourseList />
</div>
);
}
export default App;
CIIT Training Institute
- React JS
- .NET Full Stack
03 Component Tree Diagram
This diagram shows the hierarchy of an institute website.
The App component contains a Header, MainContent
and Footer. MainContent contains the course and student sections.
04 Building a Nested Component Tree
Let's create a small course page where App renders
CourseSection, and CourseSection renders
CourseTitle and CourseDetails.
function CourseTitle() {
return <h2>React JS Training</h2>;
}
function CourseDetails() {
return (
<div>
<p>Learn JSX and components.</p>
<p>Build practical projects at CIIT Training Institute.</p>
</div>
);
}
function CourseSection() {
return (
<section>
<CourseTitle />
<CourseDetails />
</section>
);
}
function App() {
return <CourseSection />;
}
export default App;
React JS Training
Learn JSX and components.
Build practical projects at CIIT Training Institute.
05 Student Profiles Component Tree
A parent can render a reusable StudentCard component several times. Each card receives different props, while the component structure stays the same.
function StudentCard({ name, course }) {
return (
<div>
<h3>{name}</h3>
<p>Course: {course}</p>
</div>
);
}
export default StudentCard;
import StudentCard from "./StudentCard";
function StudentSection() {
return (
<section>
<h2>CIIT Student Profiles</h2>
<StudentCard
name="Samadhan"
course="React JS"
/>
<StudentCard
name="Samiksha"
course=".NET Full Stack"
/>
<StudentCard
name="Pradnya"
course="Python"
/>
</section>
);
}
function App() {
return <StudentSection />;
}
export default App;
CIIT Student Profiles
06 How to Read a Component Tree
The top-level component of the displayed component hierarchy.
A component that renders another component.
A component rendered by another component.
Components rendered by the same parent.
07 Important Rules and Best Practices
Break large interfaces into smaller components.
Use meaningful component names such as Header and StudentCard.
Pass data through props when child components need it.
Keep the component hierarchy understandable and maintainable.
Remember that rendering a component creates a component relationship in the tree.
08 Practice Questions
- Draw a component tree for a website with Header, MainContent and Footer.
- Create a CourseSection component with CourseTitle and CourseDetails.
- Build a StudentSection that renders Samadhan, Samiksha and Pradnya.
- Explain the difference between a parent and a child component.
- Identify the sibling components in the first diagram.
- Create a component tree for a simple student dashboard.
Summary
A Component Tree represents the hierarchy formed when React components render other components. The root component sits at the top, parent components render children, and components rendered by the same parent are siblings. Reusable components and props help organize the tree and display different data without repeating the UI structure. At CIIT Training Institute, practise drawing and building component trees for course pages and student profiles.