NextJs — API Caching and Revalidation
Next.js supports Incremental Static Regeneration (ISR) to revalidate pages after they’ve been built. This enables static pages to stay up-to-date.
export async function getStaticProps() {
const res = await fetch('https://jsonplaceholder.typicode.com/posts/1');
const post = await res.json();
return {
props: { post },
revalidate: 60, // re-generate page every 60 seconds
};
}
export default function Post({ post }) {
return <h1>{post.title}</h1>;
}