0
0
Astroframework~20 mins

Incremental builds with data in Astro - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Incremental Build Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What is the output of this Astro component using incremental data?

Consider this Astro component that fetches data incrementally during build:

---
const response = await fetch('https://api.example.com/items');
const items = await response.json();
---
    {items.map(item => (
  • {item.name}
  • ))}

What will this component render if the API returns [{"name": "Apple"}, {"name": "Banana"}]?

Astro
---
const response = await fetch('https://api.example.com/items');
const items = await response.json();
---
<ul>
  {items.map(item => (
    <li>{item.name}</li>
  ))}
</ul>
A<ul><li>Apple</li><li>Banana</li></ul>
B<ul></ul>
C<ul><li>undefined</li><li>undefined</li></ul>
D<ul><li>{item.name}</li><li>{item.name}</li></ul>
Attempts:
2 left
💡 Hint

Think about how the map function transforms each item into a list element.

state_output
intermediate
1:30remaining
What is the value of the variable after incremental data fetch?

In an Astro component, this code runs during build:

---
let count = 0;
const data = await fetch('https://api.example.com/count');
const json = await data.json();
count = json.value;
---

What is the value of count if the API returns {"value": 42}?

Astro
---
let count = 0;
const data = await fetch('https://api.example.com/count');
const json = await data.json();
count = json.value;
---
Anull
Bundefined
C42
D0
Attempts:
2 left
💡 Hint

Remember the assignment count = json.value updates the variable.

📝 Syntax
advanced
2:00remaining
Which option correctly uses Astro's incremental build data fetching syntax?

Choose the correct way to fetch data incrementally in an Astro component:

A
---
const response = fetch('https://api.example.com/data');
const data = response.json();
---
B
---
const response = await fetch('https://api.example.com/data');
const data = await response.json();
---
C
---
const response = await fetch('https://api.example.com/data')
const data = await response.json()
---
D
---
const response = await fetch('https://api.example.com/data');
const data = response.json();
---
Attempts:
2 left
💡 Hint

Check for proper use of await and semicolons.

🔧 Debug
advanced
2:30remaining
Why does this Astro incremental build code cause a runtime error?

Given this Astro component code:

---
const response = await fetch('https://api.example.com/items');
const items = response.json();
---
    {items.map(item =>
  • {item.name}
  • )}

What causes the runtime error?

Astro
---
const response = await fetch('https://api.example.com/items');
const items = response.json();
---
<ul>
  {items.map(item => <li>{item.name}</li>)}
</ul>
AMissing await before response.json(), so items is a Promise, not an array
BUsing map on items is invalid because items is null
Cfetch URL is incorrect causing network error
DUsing <li> inside <ul> is invalid HTML
Attempts:
2 left
💡 Hint

Check if all async calls are awaited properly.

🧠 Conceptual
expert
3:00remaining
How does Astro's incremental build with data improve site performance?

Which statement best explains the benefit of using incremental builds with data in Astro?

AIt disables caching to force full rebuilds for every change, improving accuracy
BIt fetches all data on every user request, ensuring always fresh content but slower response
CIt pre-renders all pages at once regardless of data changes, increasing build time
DIt rebuilds only pages with changed data, reducing build time and improving deployment speed
Attempts:
2 left
💡 Hint

Think about how incremental builds save time by avoiding unnecessary work.