Complete the code to fetch data during build time in Astro.
export async function getStaticPaths() {
const data = await fetch('/api/data').then(res => res.json());
return {
paths: data.map(item => ({ params: { id: item.id } })),
[1]: false
};
}The fallback property controls whether Astro should generate pages for paths not returned by getStaticPaths. Setting it to false disables fallback pages.
Complete the code to define a dynamic route parameter in Astro.
---
const { params } = Astro;
const id = [1];
---Astro.id directly.params.route which does not exist.Dynamic route parameters are accessed via params. Here, params.id gets the id from the URL.
Fix the error in the code to correctly export a data fetching function for incremental builds.
export async function [1]() { const response = await fetch('https://api.example.com/items'); const items = await response.json(); return items; }
getStaticProps which don't exist in Astro.getData.In Astro, getStaticPaths is used to fetch data for incremental static generation of pages.
Fill both blanks to create a dictionary comprehension that filters data during build.
const filteredData = Object.fromEntries( Object.entries(data).filter(([key, value]) => value.[1] [2] 10) );
This code filters entries where the score is greater than 10.
Fill all three blanks to create a map of uppercase keys to values filtered by a condition.
const result = Object.fromEntries(
Object.entries(data)
.filter(([[1], [2]]) => [2] > 0)
.map(([key, value]) => [key.[3](), value])
);This code filters entries where the value is greater than zero, then maps keys to uppercase.