Props are inputs passed to a component to customize its content or behavior. They let you send data from a parent component to a child component.
Click to reveal answer
beginner
How does component composition work in Astro?
Component composition means building complex UI by combining smaller components. You put child components inside parent components to reuse and organize code.
Click to reveal answer
beginner
How do you pass props to a child component in Astro?
You add attributes to the child component tag with the prop names and values. For example: <Child name="Alice" /> passes a prop called name with value "Alice".
Click to reveal answer
intermediate
Why is using props better than hardcoding values inside components?
Props make components flexible and reusable. Instead of repeating code, you change the input data to get different results without changing the component itself.
Click to reveal answer
intermediate
What happens if a required prop is missing in an Astro component?
If a prop is missing, the component may show default content or cause errors depending on how it handles missing data. It's good to provide default values or check props inside the component.
Click to reveal answer
How do you send data from a parent to a child component in Astro?
ABy using global variables
BBy importing the child component inside the parent
CBy writing data inside the child component only
DBy passing props as attributes on the child component tag
✗ Incorrect
Props are passed as attributes on the child component tag to send data from parent to child.
What is component composition in Astro?
AWriting all code in one big component
BCombining smaller components inside bigger ones
CUsing only built-in HTML tags
DPassing props without components
✗ Incorrect
Component composition means building UI by combining smaller components inside bigger ones.
Which syntax correctly passes a prop named 'title' with value 'Hello' to a component Card?
A<Card title="Hello" />
B<Card 'title' = Hello />
C<Card title: Hello />
D<Card {title: 'Hello'} />
✗ Incorrect
Props are passed as attributes with name and value pairs like .
Why should you use props instead of hardcoding values inside components?
ATo make components reusable and flexible
BTo make components slower
CTo avoid using components
DTo write more code
✗ Incorrect
Props allow components to be reused with different data, making them flexible.
What is a good practice when a prop might be missing in a component?
AIgnore missing props and do nothing
BAlways crash the app
CProvide default values or check props inside the component
DRemove the component
✗ Incorrect
Providing default values or checking props helps avoid errors when props are missing.
Explain how props work in Astro and why they are important for component composition.
Think about how you pass information from a parent to a child in a family.
You got /4 concepts.
Describe how you would compose a parent component using two child components with different props in Astro.
Imagine building a sandwich with different ingredients as child components.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of props in Astro components?
easy
A. To pass data from a parent component to a child component
B. To style components with CSS
C. To handle user events like clicks
D. To fetch data from a server
Solution
Step 1: Understand the role of props
Props are used to send data from a parent component to a child component in Astro.
Step 2: Differentiate from other uses
Props are not for styling, event handling, or data fetching directly; those are separate concerns.
Final Answer:
To pass data from a parent component to a child component -> Option A
Quick Check:
Props = data passing [OK]
Hint: Props always send data down from parent to child [OK]
Common Mistakes:
Thinking props handle events
Confusing props with CSS styling
Assuming props fetch data
2. Which of the following is the correct way to pass a prop named title with value "Hello" to a child component <MyComponent /> in Astro?
easy
A. <MyComponent {title: "Hello"} />
B. <MyComponent title=>Hello</MyComponent>
C. <MyComponent title={Hello} />
D. <MyComponent title="Hello" />
Solution
Step 1: Recall Astro prop syntax
Props are passed as HTML-like attributes with string values in quotes.
Step 2: Check each option
<MyComponent title="Hello" /> uses correct syntax: title="Hello". <MyComponent {title: "Hello"} /> uses object syntax which is invalid. <MyComponent title={Hello} /> misses quotes around Hello. <MyComponent title=>Hello</MyComponent> uses children syntax which is not how props are passed.
Final Answer:
<MyComponent title="Hello" /> -> Option D
Quick Check:
Props = attribute="value" [OK]
Hint: Props look like HTML attributes with quoted values [OK]
What will be rendered if the parent uses <Child message="Hi!" />?
medium
A. <div>{message}</div>
B. <div>Hi!</div>
C. An error because message is not defined
D. <div></div>
Solution
Step 1: Understand prop extraction
The component extracts message from Astro.props, which receives the prop from the parent.
Step 2: Check rendering output
The JSX-like syntax outputs the value of message inside a <div>, so it renders <div>Hi!</div>.
Final Answer:
<div>Hi!</div> -> Option B
Quick Check:
Prop value = rendered content [OK]
Hint: Props become variables inside the component [OK]
Common Mistakes:
Thinking JSX shows literal {message}
Assuming missing prop causes error
Expecting empty div if prop exists
4. Identify the error in this Astro component usage:
<ChildComponent message=Hello />
medium
A. Props must be passed as children, not attributes
B. ChildComponent cannot receive props
C. Missing quotes around the string Hello
D. The component tag must be self-closing with a semicolon
Solution
Step 1: Check prop syntax
Props with string values must be enclosed in quotes in Astro.
Step 2: Identify the error
The code passes message=Hello without quotes, causing a syntax error.
Final Answer:
Missing quotes around the string Hello -> Option C
Quick Check:
String props need quotes [OK]
Hint: Always quote string prop values [OK]
Common Mistakes:
Omitting quotes around strings
Thinking props are passed as children
Adding unnecessary semicolons
5. You want to create a parent component that renders a list of Item components, each receiving a name prop from an array ['Apple', 'Banana', 'Cherry']. Which Astro code correctly composes these components?