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.
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.
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.
<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.
App component
name, price
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.
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.
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.
{ 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.
Root
Logo + Nav
Root
Maps over array
Single product
.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.
Test your knowledge
props.children contain?function Card({ title, color = 'blue' }), what is color when you write <Card title="Hello" />?.map(), why does each element need a key prop?🏆 Challenge: Build an UrbanCart Product Page
Combine everything from this lesson to build a mini product page with these components:
- Header — Takes a
storeNameprop and renders the store title with a cart icon. - ProductCard — Takes
name,price,image, andinStockprops with sensible defaults. - ProductList — Receives an array of products and maps over them, rendering
ProductCardfor each. - Footer — A wrapper component using
childrenfor flexible content. - 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.
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 →