Introduction to React Components
Learn how React components help you build reusable, organized, and maintainable user interfaces for CIIT Training Institute.
1. What Are React Components?
A React component is a reusable piece of a user interface. It can represent a heading, student card, navigation bar, course section, or an entire page.
Components help developers divide a large application into smaller and easier-to-manage parts.
function App() {
return (
<div>
<h1>CIIT Training Institute</h1>
<p>Learn programming step by step.</p>
</div>
);
}
export default App;
Expected Output
CIIT Training Institute
Learn programming step by step.
2. React Component Diagram
A page can be divided into smaller components. The main App component can combine a Header, CourseList, and Footer.
function Header() {
return <h1>CIIT Training Institute</h1>;
}
function CourseList() {
return <p>Explore our programming courses.</p>;
}
function Footer() {
return <footer>Learn. Practice. Grow.</footer>;
}
function App() {
return (
<div>
<Header />
<CourseList />
<Footer />
</div>
);
}
export default App;
Expected Output
CIIT Training Institute
Explore our programming courses.
3. Creating Your First Component
To create a functional component, define a JavaScript function that returns JSX. Component names should begin with an uppercase letter.
function StudentProfile() {
return (
<div>
<h2>Samadhan</h2>
<p>Course: React JS</p>
<p>Institute: CIIT Training Institute</p>
</div>
);
}
export default StudentProfile;
You can render this component inside another component
using <StudentProfile />.
import StudentProfile from "./StudentProfile";
function App() {
return (
<div>
<h1>Student Dashboard</h1>
<StudentProfile />
</div>
);
}
export default App;
Expected Output
Student Dashboard
Samadhan
Course: React JS
Institute: CIIT Training Institute
4. Why Are Components Reusable?
A reusable component can be used multiple times. Instead of writing the same student card markup repeatedly, you can create a component and reuse it.
function StudentCard({ name, course }) {
return (
<div className="student-card">
<h3>{name}</h3>
<p>Course: {course}</p>
<p>CIIT Training Institute</p>
</div>
);
}
export default StudentCard;
import StudentCard from "./StudentCard";
function App() {
return (
<div>
<h2>Our Students</h2>
<StudentCard
name="Samadhan"
course="React JS"
/>
<StudentCard
name="Samiksha"
course=".NET Full Stack"
/>
<StudentCard
name="Pradnya"
course="Python"
/>
</div>
);
}
export default App;
Expected Output
Our Students
Samadhan
Course: React JS
CIIT Training Institute
Samiksha
Course: .NET Full Stack
CIIT Training Institute
Pradnya
Course: Python
CIIT Training Institute
5. Component Naming Rules
React components should use PascalCase names. This means each word starts with a capital letter.
| Name | Valid? | Reason |
|---|---|---|
StudentCard |
Yes | Starts with an uppercase letter. |
CourseList |
Yes | Uses PascalCase. |
studentCard |
No, for a custom component | Starts with a lowercase letter. |
course-list |
No, for a component name | Hyphenated names are not component identifiers. |
div represent
built-in elements. Use uppercase names for your own
React components.
6. Component Composition
Component composition means combining smaller components to build a larger user interface.
function CourseHeading() {
return <h2>CIIT Training Institute Courses</h2>;
}
function CourseDetails() {
return (
<div>
<p>React JS</p>
<p>.NET Full Stack</p>
<p>Python</p>
</div>
);
}
function CourseSection() {
return (
<section>
<CourseHeading />
<CourseDetails />
</section>
);
}
export default CourseSection;
Expected Output
CIIT Training Institute Courses
React JS
.NET Full Stack
Python
7. React Components Best Practices
- Give each component a clear and meaningful name.
- Keep components focused on a specific responsibility.
- Reuse components instead of repeating the same markup.
- Use props to pass data to reusable components.
- Keep JSX indentation consistent and readable.
- Export and import components using the appropriate syntax.
- Use CIIT Training Institute branding consistently across institute pages.
8. Practice Questions
- Create a component that displays CIIT Training Institute's name.
- Create a StudentProfile component for Samadhan.
- Build one reusable StudentCard component for Samiksha and Pradnya.
- Create separate Header, CourseList, and Footer components.
- Combine three smaller components inside an App component.
- Explain why custom component names should start with uppercase letters.
Summary
React components are reusable building blocks for user interfaces. They allow CIIT Training Institute pages to be divided into smaller parts such as headers, course lists, and student cards. Components can be combined through composition, reused with different data, and organized with clear naming conventions. Functional components return JSX and can receive props to display dynamic information for students such as Samadhan, Samiksha, and Pradnya.