What is static site generation (SSG) in React frameworks like Next.js?
Static Site Generation (SSG) is a technique where HTML pages are generated at build
time. Unlike SSR, SSG pre-renders all pages during the build process, which results in
faster load times.
Example with Next.js (SSG):
import React from 'react';
export async function getStaticProps() {
const data = await fetchDataFromAPI();
return { props: { data } };
}
function Page({ data }) {
return <div>{data}</div>;
}
export default Page;
Here, getStaticProps is a Next.js function that fetches data during build time. The page
is pre-rendered and served as static HTML.