JavaScript Curriculum
Props
easyThe MenuCard component is written once but needs to display different items — Espresso, Cappuccino, Cold Brew. Props are how you pass the right name, price, and emoji to each instance without duplicating code.
Props
Props (properties) are the inputs to a React component. The parent controls what data the child gets — the child renders it. This one-way flow is the foundation of React's predictable data model.
How Props Flow
Data moves down, callbacks bubble up:
<MenuCard name="Espresso" price={2.50} featured={true} emoji="☕" onOrder={handleOrder} />
function MenuCard({ name, price, featured, emoji, onOrder, }) { ... }
Five Prop Patterns You Need
Required props, defaults, spread, children, and callbacks:
Props with no default value are required. If missing, the value is undefined — which can cause runtime errors.
function MenuCard({ name, price }) { // name and price are REQUIRED // If not passed: name = undefined, price = undefined return <div>{name} — £{price.toFixed(2)}</div> // 💥 TypeError if price is undefined } // ✓ Always pass required props: <MenuCard name="Espresso" price={2.50} />
Live Props Playground
Change prop values and see the component and JSX update instantly:
<Button label="Order Now" variant="primary" />
Your Challenge
Write a Menu component that receives items (array of objects) and onOrder (function) as props. Map over items to render a MenuCard for each. Pass onOrder down to each MenuCard which calls it with the item object when its button is clicked. Use spread: <MenuCard {...item} onOrder={onOrder} />.
Challenge
Write a Menu component that receives an items array as a prop and renders a MenuCard for each one. Add an onOrder callback prop to MenuCard that the parent wires to an addToCart function. Use the spread operator to pass item objects directly.
Props
easyThe MenuCard component is written once but needs to display different items — Espresso, Cappuccino, Cold Brew. Props are how you pass the right name, price, and emoji to each instance without duplicating code.
Props
Props (properties) are the inputs to a React component. The parent controls what data the child gets — the child renders it. This one-way flow is the foundation of React's predictable data model.
How Props Flow
Data moves down, callbacks bubble up:
<MenuCard name="Espresso" price={2.50} featured={true} emoji="☕" onOrder={handleOrder} />
function MenuCard({ name, price, featured, emoji, onOrder, }) { ... }
Five Prop Patterns You Need
Required props, defaults, spread, children, and callbacks:
Props with no default value are required. If missing, the value is undefined — which can cause runtime errors.
function MenuCard({ name, price }) { // name and price are REQUIRED // If not passed: name = undefined, price = undefined return <div>{name} — £{price.toFixed(2)}</div> // 💥 TypeError if price is undefined } // ✓ Always pass required props: <MenuCard name="Espresso" price={2.50} />
Live Props Playground
Change prop values and see the component and JSX update instantly:
<Button label="Order Now" variant="primary" />
Your Challenge
Write a Menu component that receives items (array of objects) and onOrder (function) as props. Map over items to render a MenuCard for each. Pass onOrder down to each MenuCard which calls it with the item object when its button is clicked. Use spread: <MenuCard {...item} onOrder={onOrder} />.
Challenge
Write a Menu component that receives an items array as a prop and renders a MenuCard for each one. Add an onOrder callback prop to MenuCard that the parent wires to an addToCart function. Use the spread operator to pass item objects directly.