Complete the code to export a Next.js page that uses static generation.
export async function [1]() { return { props: { message: 'Hello' } }; } export default function Home({ message }) { return <h1>{message}</h1>; }
The getStaticProps function tells Next.js to generate the page at build time (static generation).
Complete the code to export a Next.js page that uses server-side rendering.
export async function [1](context) { return { props: { time: new Date().toISOString() } }; } export default function TimePage({ time }) { return <p>Current time: {time}</p>; }
The getServerSideProps function runs on each request, enabling server-side rendering.
Fix the error in the code to enable dynamic rendering with fallback blocking.
export async function getStaticPaths() {
return {
paths: [],
fallback: [1]
};
}
export async function getStaticProps({ params }) {
return { props: { id: params.id } };
}
export default function Page({ id }) {
return <p>ID: {id}</p>;
}Setting fallback to 'blocking' enables dynamic rendering where the page is generated on demand and cached.
Fill both blanks to create a Next.js API route that triggers revalidation for a page.
export default async function handler(req, res) {
await res.[1]('/path-to-revalidate');
res.status([2]).json({ message: 'Revalidated' });
}The res.revalidate method triggers Next.js to regenerate the page at the given path. Then a 200 status is sent to confirm success.
Fill both blanks to create a Next.js page that uses ISR with revalidate time and fallback blocking.
export async function getStaticPaths() {
return {
paths: [],
fallback: [1]
};
}
export async function getStaticProps() {
return {
props: { time: new Date().toISOString() },
revalidate: [2]
};
}
export default function ISRPage({ time }) {
return <p>Generated at: {time}</p>;
}Setting fallback to 'blocking' enables on-demand page generation. The revalidate value sets the seconds before regeneration to 10.