Composing components
Exercise35 min
Composing components
Components take components as children. That single idea builds whole pages:
function Page() {
return (
<main>
<Header />
<CardGrid lessons={lessons} />
<Footer />
</main>
);
}
function CardGrid({ lessons }) {
return lessons.map((l) => <LessonRow key={l.id} {...l} />);
}The rule that keeps this sane: each component does one job. When a component answers two questions, split it. And every list child needs a stable key — React uses it to match rows between renders, and getting it wrong causes state to stick to the wrong row.
Exercise
Compose Header, LessonList, LessonRow, Footer into one page. Pass lesson data down as props.
Practice in the diagram lab
This lesson's practice belongs in the diagram editor — design the schema you just read about, grade it against the solution, and save it to your account.
Open the diagram lab