Components
Master React components, the reusable and independent pieces of code that assemble to build stunning user interfaces.
Learning Goals
The Core Concept
Components are the heartbeat of React. Instead of managing a single massive HTML file, React splits the interface into small, isolated elements. There are two benefits: reusability and maintainability. For instance, you can write a Button component once and use it in 20 different places with different colors or text.
A React component is just a standard JavaScript function that returns JSX. In modern React, we use Function Components exclusively (avoiding old ES6 Class components). We can combine multiple child components inside a larger parent component to construct complex pages.
Visual guide
React concept flow
A simple original diagram to connect the lesson idea with real project flow.
Code & Implementation
// 1. Child Component
function WelcomeMessage() {
return <p>Thanks for visiting! We hope you learn something new today.</p>;
}
// 2. Parent Component (Container)
export default function HomePage() {
return (
<main style={{ padding: '24px' }}>
<h1>Dashboard Home</h1>
{/* Reusing the child component */}
<WelcomeMessage />
<WelcomeMessage />
</main>
);
}Expected Output
UI preview: - Heading 'Dashboard Home' - Paragraph 'Thanks for visiting!...' - Second duplicate Paragraph 'Thanks for visiting!...'
Build a Simple Navigation Bar
Hands-on practice task
The Challenge
Create a NavBar component. Inside, render a custom child component named NavLink three times with different names to build a header navigation skeleton.
Helpful Hints
- •Define NavLink component returning a styled list item <li>.
- •Define NavBar component returning a <nav> and an unordered list <ul> containing three <NavLink /> elements.
Quick Knowledge Check
Can components call other components?
Do I have to export every component?
Continue Learning
Next steps after this lesson
Create a NavBar component. Inside, render a custom child component named NavLink three times with different names to build a header navigation skeleton.
Supercharge your career workflows!
Discover free online utilities to format data, build job applications, and automate your productivity routine with TechIdea.