Cats
import { useData } from 'nextra/hooks'
export async function getStaticProps() {
// Hacer una solicitud de datos en tiempo de compilación
const catURL= "https://api.thecatapi.com/v1/images/search?size=full"
const res = await fetch(catURL);
const cats = await res.json();
return {
props: { // We add an `ssg` field to the page props, which will be provided to the Nextra `useData` hook.
ssg: {
cats: cats
}
},
// The page will be considered as stale and regenerated every 60 seconds.
revalidate: 60
};
}
export function Stars() {
// Get the data from SSG, and render it as a component.
const { stars } = useData()
return <strong>{stars}</strong>
}
export function Cats() {
const { cats } = useData()
return (
<div>
<ul>
{cats.map(cat => (
<li key={cat.id}><img src={cat.url} width={cat.width} />
</li>
))}
</ul>
</div>
);
}
## Cats
<Cats />