astrobench · play with code
Step
4/11

Pass them around

Mission Control sends many astronauts. Make the card take a name.

Mission Control sends many astronauts. We can't hardcode every name inside the card — it'd defeat the point of having a component.

 

Time for props . The card pulls name and mission from Astro.props — any page can pass different values in as HTML attributes.

 

The preview feeds name="Mae" mission="Endeavour" into your Card. Try changing the heading or destructuring an extra prop.

src/components/Card.astro — now reusable live

And on the page that uses it — pass the values like attributes:

src/pages/index.astro read-only
1
2
3
4
5
6
7
---
import Card from "~/components/Card.astro";
---

<Card name="Mae" mission="Endeavour" />
<Card name="Ovidiu" mission="Apollo 42" />
<Card name="Sergei" mission="Soyuz 11" />

Three cards. One component. That's the whole trick.

— page 4 —
in the binder open binder →
saved a moment ago
progress 36%
earn +75 XP