βοΈ React Components (Topic 3)

Table of contents
- β What is a Component in React?
- π§© Types of Components
- π Creating & Exporting Components
- π₯ Importing & Using Components
- π Component Naming Conventions
- π§βπ« Real-Life Analogy
- π‘ Export & Import Tips (for Professionals)
- β Summary
- π§ͺ Mini Project for Topic 3: "Profile Card Component"

β What is a Component in React?
A component is like a reusable building block in React.
Just like a house is made of bricks, a React app is made of components.
Example: A website may have a Header, Footer, Sidebar, and ProductCard β all can be separate components.
π§© Types of Components
There are 2 main types of components in React:
1. Function Components (Most Common)
Simple JavaScript functions
Easy to write and understand
Support React Hooks (
useState
,useEffect
, etc.)
β Example:
//jsx
function Welcome() {
return <h1>Welcome to React!</h1>;
}
2. Class Components (Older Way)
Use ES6
class
keywordHave
render()
methodUsed before hooks were introduced
π§ Example:
//jsx
import React, { Component } from 'react';
class Welcome extends Component {
render() {
return <h1>Welcome to React!</h1>;
}
}
β οΈ Today, we mostly use function components with hooks β simpler and modern.
π Creating & Exporting Components
Letβs create a simple component step-by-step:
π Folder Structure:
src/
βββ components/
βββ Welcome.js
π Welcome.js:
//jsx
import React from 'react';
function Welcome() {
return <h2>Hello from Welcome Component!</h2>;
}
export default Welcome;
β Here:
We created a component using a function
Then exported it using
export default
π₯ Importing & Using Components
Now we want to use Welcome
component inside App.js
.
π§Ύ App.js:
//jsx
import React from 'react';
import Welcome from './components/Welcome'; // β¬
οΈ Import
function App() {
return (
<div>
<h1>Main App</h1>
<Welcome /> {/* β¬
οΈ Using Component */}
</div>
);
}
export default App;
β This will show:
Main App
Hello from Welcome Component!
π Component Naming Conventions
Here are some best practices for naming components:
Rule | Example |
Component name must start with capital letter | Welcome , not welcome |
File name should match component name | Welcome.js β function Welcome() |
Use PascalCase for component names | ProductCard , UserProfile |
Keep components in a separate components/ folder | For better structure |
π§βπ« Real-Life Analogy
Think of components like LEGO blocks. You create small parts and join them together to build the full website (UI). Each block (component) is reusable and independent.
π‘ Export & Import Tips (for Professionals)
Use Case | Code |
Default Export (only one per file) | export default Welcome; β import Welcome from './Welcome' |
Named Export (multiple exports) | export { Welcome }; β import { Welcome } from './Welcome' |
Aliasing while import | import MyWelcome from './Welcome'; |
Grouped imports | import Header from './Header'; import Footer from './Footer'; |
β Summary
Components are reusable UI pieces
React has function and class components (function preferred)
Components must be exported and imported properly
Naming should follow PascalCase and organized in folders
π§ͺ Mini Project for Topic 3: "Profile Card Component"
π― Goal:
Create a small reusable Profile Card component using function components, import/export, and apply naming conventions.
β Project Features:
Show a profile card with:
Profile Picture (you can use a random image URL)
Name
Role (e.g., Web Developer, Student, etc.)
A short description
Use multiple components:
App.js
ProfileCard.js
Optional:
Header.js
,Footer.js
π Suggested File Structure:
src/
βββ App.js
βββ components/
βββ ProfileCard.js
βββ Header.js
βββ Footer.js
π§Ύ Sample ProfileCard.js
:
//jsx
import React from 'react';
import './ProfileCard.css';
function ProfileCard() {
return (
<div className="card">
<img src="https://randomuser.me/api/portraits/men/75.jpg" alt="profile" />
<h2>Rahul Sharma</h2>
<p>Frontend Developer</p>
<p>I love building beautiful and responsive UIs with React.</p>
</div>
);
}
export default ProfileCard;
π§Ύ Sample App.js
:
//jsx
import React from 'react';
import ProfileCard from './components/ProfileCard';
function App() {
return (
<div>
<h1>Team Members</h1>
<ProfileCard />
<ProfileCard />
</div>
);
}
export default App;
π¨ Optional Styling (ProfileCard.css):
.card {
border: 1px solid #ccc;
padding: 16px;
border-radius: 12px;
width: 250px;
text-align: center;
box-shadow: 2px 2px 8px #ddd;
margin: 20px auto;
}
.card img {
width: 100px;
border-radius: 50%;
}
π Assignment for Students (Topic 3: Components)
π Instructions:
Create the following using React Functional Components:
Header Component
- Show the name of your site like "My Portfolio"
Footer Component
- Include your name and year (e.g., βΒ© 2025 by Riya Sharmaβ)
ProfileCard Component
Reusable card that takes:
Name
Role
Image URL
Display at least 3 cards with different data
π¦ Deliverables:
Must use proper component naming conventions
Code must be modular (each component in its own file)
Use of
export
andimport
should be correctUse props if you want to go advanced (covered in next topic, optional for now)
π‘ Extra Challenge (for Working Professionals):
Add a button in each ProfileCard like βContactβ or βFollowβ
Use
onClick
to show an alert (onClick={() => alert("You clicked!")}
)
Would you like me to:
explain things in more detail?
continue with the next topic: Props (Topic 4)?
Let me know how you'd like to proceed!
π Stay Connected
If you found this article helpful and want to receive more such beginner-friendly and industry-relevant React notes, tutorials, and project ideas β
π© Subscribe to our newsletter by entering your email below.
And if you're someone who wants to prepare for tech interviews while having a little fun and entertainment,
π₯ Donβt forget to subscribe to my YouTube channel β Knowledge Factory 22 β for regular content on tech concepts, career tips, and coding insights!
Stay curious. Keep building. π
Subscribe to my newsletter
Read articles from Payal Porwal directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Payal Porwal
Payal Porwal
Hi there, tech enthusiasts! I'm a passionate Software Developer driven by a love for continuous learning and innovation. I thrive on exploring new tools and technologies, pushing boundaries, and finding creative solutions to complex problems. What You'll Find Here On my Hashnode blog, I share: π In-depth explorations of emerging technologies π‘ Practical tutorials and how-to guides π§Insights on software development best practices πReviews of the latest tools and frameworks π‘ Personal experiences from real-world projects. Join me as we bridge imagination and implementation in the tech world. Whether you're a seasoned pro or just starting out, there's always something new to discover! Letβs connect and grow together! π