1. Functional Components

A React component is just a JavaScript function that returns JSX. That's it. The function name starts with a capital letter, and what it returns is what shows up on screen.

🛒
UrbanCart Example
Every product card is a component

On UrbanCart's product listing page, each product card looks the same — an image, a name, a price, and a stock badge. Instead of writing that HTML structure 50 times, you write one ProductCard component and reuse it for every product.

ProductCard.jsx Your First Component
📐

Rules for Components

Name must start with a capital letter. Must return JSX (or null). Use className instead of class.

♻️

Why Components?

Reusability — write once, use everywhere. Isolation — each component manages its own piece of UI.

Key insight: A component is a function. It returns JSX. React calls that function and puts the result on the page. Every time you write <ProductCard />, React calls the ProductCard function.

2. Props — Passing Data to Components

The ProductCard above is hardcoded — it always shows "Wireless Headphones." That's not useful. Props let you pass different data to the same component, like function arguments.

props-basics.jsx Props = Function Arguments
Props are read-only. A component must never modify its own props. Think of props as arguments you receive — you use them, you don't change them. If data needs to change, that's what state is for (next lesson).
How Props Flow
Parent
App component
→
Props
name, price
→
Child
ProductCard

3. Props Destructuring

Writing props.name, props.price, props.inStock everywhere gets tedious. Destructuring pulls out the values you need right in the function signature.

destructuring.jsx Clean and Readable
Convention: Nearly all React developers use destructuring. It makes the component signature tell you exactly what data the component expects — like a contract.

4. The Children Prop

When you put content between a component's opening and closing tags, React passes it as props.children. This is how you build wrapper and container components.

children.jsx Wrapper Components
📦

Layout Components

Use children for page layouts, modals, sidebars — anything that wraps other content without knowing what's inside.

🎨

Styled Wrappers

A Card, Panel, or Section component adds consistent styling. Children provide the actual content.

5. Default Props

Sometimes a prop is optional. Default values let you define what happens when a prop isn't passed. Use JavaScript's default parameter syntax right in the destructuring.

defaults.jsx Sensible Defaults
Tip: Default props are just JavaScript defaults — nothing React-specific. { name, price = 0 } means "if price isn't passed, use 0." Simple, powerful, and no extra API to learn.

6. Component Composition

Real UIs are built by composing small components into bigger ones. UrbanCart's product page isn't one giant component — it's a tree of focused, reusable pieces.

UrbanCart Component Tree
App
Root
→
Header
Logo + Nav
App
Root
→
ProductList
Maps over array
→
ProductCard
Single product
composition.jsx Building Up from Small Pieces
The key prop: When rendering a list with .map(), every element needs a unique key prop. React uses keys to efficiently update the DOM when items change. Use IDs from your data, never array indices.

Try It Yourself #1

Build UrbanCart product cards: a ProductCard component receiving name, price, and image as props. A ProductList maps over an array and renders each card.

🛠️ Try It Yourself — UrbanCart Product Cards
Output

Try It Yourself #2

Build a reusable Button component. It uses the children prop for label text and a variant prop to switch between "primary" and "outline" styles.

🛠️ Try It Yourself — Reusable Button Component
Output

Test your knowledge

Question 1 of 5
What is a React component?
Question 2 of 5
Why must you never modify props inside a component?
Question 3 of 5
What does props.children contain?
Question 4 of 5
Given function Card({ title, color = 'blue' }), what is color when you write <Card title="Hello" />?
Question 5 of 5
When rendering a list with .map(), why does each element need a key prop?
0
/5
Great job!

🏆 Challenge: Build an UrbanCart Product Page

Combine everything from this lesson to build a mini product page with these components:

  1. Header — Takes a storeName prop and renders the store title with a cart icon.
  2. ProductCard — Takes name, price, image, and inStock props with sensible defaults.
  3. ProductList — Receives an array of products and maps over them, rendering ProductCard for each.
  4. Footer — A wrapper component using children for flexible content.
  5. App — Composes Header, ProductList, and Footer together.

Bonus: add a Badge component that takes a variant prop ("success" or "warning") and renders the stock status.

Up Next

Lesson 15: State & useState →
Components display data. State makes it interactive. Next up: making UrbanCart respond to user actions.
Africa & India's Best AI Academy
🤖 AI-first 🎓 Placement Assistance

You just built React components.
Now build a full-stack career.

Join the Best AI Programs — three 5-month courses, fully online, with placement assistance. Week 1 is free.

Explore our AI-era courses →