Passing props
Fill-gap25 min
Passing props
Props are read-only arguments flowing down the tree:
function Badge({ lab }) {
return <span className="badge">{lab}</span>;
}
<Badge lab="Code Lab" />Two rules:
- Props flow one way: parent → child. A child never edits its props.
- Data has one owner. If two components need the same value, it lives in
their closest common parent.
Breaking either rule does not fail loudly — it fails eventually, with state that stops updating in sync. Keep the flow one-directional and debugging stays boring.
Exercise
Build LessonCard receiving lesson (title, minutes, lab) and onToggle. The card shows a badge and a complete toggle that calls the parent's function.