LESSON 03 / 05

Components & Props

Split the UI into small components and pass them data with props — like function arguments for UI.

🎓Mediumlevel
⏱️35 minto finish
✏️1activities

📂 Components & JSX🏷️ React

🎯 By the end of this lesson you can…

  • Create and nest components
  • Pass props and read them with destructuring
  • Use children and default values
⚛️ React App.jsx 👆 Tap a line to explain it
1function Badge({ label, color = "#8b5cf6" }) {2  return <span style={{ background: color, color: "#fff", padding: "2px 10px", borderRadius: 99, marginRight: 6 }}>{label}</span>;3}4 5function Card({ title, children }) {6  return (7    <div style={{ border: "2px solid #ddd", borderRadius: 16, padding: 14, margin: "10px 0" }}>8      <h3 style={{ marginTop: 0 }}>{title}</h3>9      {children}10    </div>11  );12}13 14function App() {15  return (16    <>17      <Card title="Asha">18        <Badge label="Pseudocode" />19        <Badge label="React" color="#0ea5e9" />20      </Card>21      <Card title="Ben">22        <Badge label="Python" color="#16a34a" />23      </Card>24    </>25  );26}
🛠️ Product card

Create a Product component that shows a product’s name and price (₹) props, then render three different products from App.

📌 Key takeaways

  • <Card title="Hi" /> passes a prop; the component receives { title }.
  • Props are read-only — a component never changes its own props.
  • children is whatever you put between the opening and closing tags.

Finished reading & practising?

Saved in this browser. Create a free account to keep it forever.