What does it mean to hydrate a component in Astro?
Hydrating a component means adding JavaScript to make it interactive after the page loads. It turns static HTML into a live, interactive part of the page.
Click to reveal answer
beginner
When should you keep a component static in Astro?
Keep a component static when it only shows content that doesn't change or need user interaction. This makes the page faster and simpler.
Click to reveal answer
beginner
What is a real-life example of when to hydrate a component?
If you have a button that changes color when clicked, you hydrate it so the button can respond to clicks and update on the page.
Click to reveal answer
intermediate
How does keeping components static improve website performance?
Static components load faster because they don’t need extra JavaScript. This means less data to download and quicker page display.
Click to reveal answer
intermediate
What are the downsides of hydrating too many components?
Hydrating many components adds more JavaScript, which can slow down the page and use more device power, making the site less efficient.
Click to reveal answer
What does hydration do in Astro?
AMakes static HTML interactive by adding JavaScript
BRemoves JavaScript from the page
CConverts JavaScript to HTML
DPrevents user interaction
✗ Incorrect
Hydration adds JavaScript to static HTML so components can respond to user actions.
When should you keep a component static?
AWhen it needs to respond to clicks
BWhen it fetches data dynamically
CWhen it animates on scroll
DWhen it only displays fixed content
✗ Incorrect
Static components are best for fixed content that does not change or need interaction.
What is a downside of hydrating many components?
AFaster page load
BSlower page and more power use
CLess JavaScript on the page
DNo user interaction
✗ Incorrect
Hydrating many components adds JavaScript, which can slow down the page and use more device resources.
Which component should you hydrate?
AA header with fixed title
BA static text paragraph
CA button that changes color when clicked
DAn image with no interaction
✗ Incorrect
Interactive elements like buttons that respond to clicks need hydration.
How does keeping components static help users?
ABy loading pages faster
BBy reducing interactivity
CBy adding more JavaScript
DBy making pages slower
✗ Incorrect
Static components load faster because they don’t require extra JavaScript.
Explain when you should hydrate a component versus keep it static in Astro.
Think about whether the component needs to respond to user actions.
You got /4 concepts.
Describe the impact of hydrating too many components on website performance.
Consider what happens when the browser has to do more work.
You got /4 concepts.
Practice
(1/5)
1. Which situation is best for keeping a component static in Astro?
easy
A. When the component only displays information and has no user interaction
B. When the component needs to update frequently based on user input
C. When the component requires real-time data fetching
D. When the component has buttons that trigger events
Solution
Step 1: Understand static components
Static components do not need to respond to user actions or update dynamically.
Step 2: Identify when to keep static
If a component only shows fixed information without interactivity, it should remain static for better performance.
Final Answer:
When the component only displays information and has no user interaction -> Option A
Quick Check:
Static = no interactivity [OK]
Hint: Static means no user interaction needed [OK]
Common Mistakes:
Thinking all components must hydrate
Hydrating components without user actions
Confusing static with dynamic updates
2. Which Astro syntax correctly hydrates a component only on client load?
easy
A. <MyComponent />
B. <MyComponent client:idle />
C. <MyComponent client:visible />
D. <MyComponent client:load />
Solution
Step 1: Recall hydration directives
Astro uses client:load to hydrate a component immediately after the page loads.
Step 2: Match syntax to behavior
client:load hydrates on load, client:idle waits for idle, client:visible hydrates when visible, and no directive means no hydration.
Final Answer:
<MyComponent client:load /> -> Option D
Quick Check:
client:load = hydrate on load [OK]
Hint: client:load hydrates immediately after page load [OK]
Common Mistakes:
Using client:idle when immediate hydration is needed
Omitting hydration directive expecting auto hydration
Confusing client:visible with client:load
3. Given this Astro component usage:
<Counter client:idle />
What happens when the page loads?
medium
A. The Counter component hydrates immediately and is interactive
B. The Counter component never hydrates and stays static
C. The Counter component hydrates only when the browser is idle
D. The Counter component hydrates only when visible on screen
Solution
Step 1: Understand client:idle behavior
The client:idle directive delays hydration until the browser is idle, improving performance.
Step 2: Predict component behavior on load
On page load, the component is static until the browser has free time, then it hydrates and becomes interactive.
Final Answer:
The Counter component hydrates only when the browser is idle -> Option C
Quick Check:
client:idle = hydrate on idle [OK]
Hint: client:idle waits for browser idle before hydrating [OK]
Common Mistakes:
Assuming immediate hydration with client:idle
Thinking client:idle means no hydration
Confusing client:idle with client:visible
4. You wrote this Astro code:
<Button client:load>Click</Button>
But the button is not interactive. What is the likely problem?
medium
A. You forgot to import the Button component
B. You used client:load on a static HTML element
C. You did not export the Button component properly
D. You need to add client:visible instead of client:load
Solution
Step 1: Check hydration on static elements
Hydration directives like client:load only work on Astro components, not plain HTML elements.
Step 2: Identify the problem in code
Using client:load on a native HTML tag like <Button> (instead of a component) does nothing, so no interactivity.
Final Answer:
You used client:load on a static HTML element -> Option B
Quick Check:
Hydrate only Astro components, not plain HTML [OK]
Hint: Hydrate only Astro components, not HTML tags [OK]
Common Mistakes:
Assuming hydration works on native HTML tags
Not importing components correctly
Confusing client:load with client:visible
5. You have a dashboard with a live chat and a static news feed. How should you hydrate these in Astro for best performance?
hard
A. Keep news feed static and hydrate chat with client:visible
B. Hydrate news feed with client:idle and chat static
C. Hydrate both chat and news feed immediately with client:load
D. Keep both static and add hydration later if needed
Solution
Step 1: Analyze component interactivity needs
The live chat requires interactivity, so it needs hydration. The news feed is static content and does not need hydration.
Step 2: Choose hydration strategy for performance
Hydrating chat with client:visible delays hydration until visible, improving load speed. Keeping news feed static avoids unnecessary hydration.
Final Answer:
Keep news feed static and hydrate chat with client:visible -> Option A