NextJs — Static Site Generation (SSG)
SSG generates HTML at build time. Use getStaticProps
to fetch data before rendering the page. Ideal for pages with content that doesn’t change frequently.
export async function getStaticProps() {
const res = await fetch('https://jsonplaceholder.typicode.com/posts/1');
const post = await res.json();
return {
props: { post },
};
}
export default function Post({ post }) {
return <h1>{post.title}</h1>;
}