Complete the code to fetch data at build time in Astro.
export async function getStaticPaths() {
const response = await fetch([1]);
const data = await response.json();
return { paths: data.map(item => ({ params: { id: item.id } })), fallback: false };
}The fetch function needs a URL string to get data from an API at build time.
Complete the code to return static props with fetched data in Astro.
export async function getStaticProps() {
const res = await fetch('https://api.example.com/items');
const items = await res.json();
return { props: { [1] } };
}The fetched JSON data is stored in items, which should be returned as props.
Fix the error in the Astro component to use fetched data correctly.
---
const { [1] } = Astro.props;
---
<h1>Item List</h1>
<ul>
{items.map(item => <li>{item.name}</li>)}
</ul>The component expects items from props to render the list.
Fill both blanks to create a static page with data fetched at build time.
export async function getStaticProps() {
const res = await fetch([1]);
const data = await res.json();
return { props: { [2] } };
}The URL to fetch posts is needed, and the JSON data variable data should be returned as props.
Fill all three blanks to fetch data and render it in Astro component.
---
const { [1] } = Astro.props;
---
<h2>Users</h2>
<ul>
{ [2].map(user => <li key={user.id}>{user.[3]</li>)}
</ul>The component destructures users from props, maps over it, and displays each user's name.
