by Ahmed Megahd
1
2
3
1
2
3
export async function getStaticProps() {
const res = await fetch('https://api.example.com/posts');
const posts = await res.json();
return {
props: { posts },
revalidate: 10, // ISR: Rebuilds page every 10 seconds
};
}
// app/routes/products/$productId.jsx
export async function loader({ params }) {
const product = await getProductById(params.productId);
if (!product) throw new Response("Not Found", { status: 404 });
return product;
}
export default function Product() {
const product = useLoaderData();
return ;
}
---
import Header from '../components/Header.astro';
import BlogPost from '../components/BlogPost.jsx';
const posts = Astro.props.posts;
---
<html>
<body>
<Header />
<main>
{posts.map(post => (
<BlogPost client:visible {...post} />
))}
</main>
</body>
</html>