Revalidation after mutation in Next.js
📖 Scenario: You are building a simple blog page using Next.js. The page shows a list of posts fetched from a server. When a new post is added, you want the page to update automatically by revalidating the data.
🎯 Goal: Create a Next.js page that fetches posts with getStaticProps, adds a new post using a server action, and triggers revalidation so the page updates with the new post.
📋 What You'll Learn
Create a
posts array with initial postsAdd a
revalidateTime variable for incremental static regenerationUse
getStaticProps to fetch posts and set revalidation timeCreate a server action to add a new post and trigger revalidation
💡 Why This Matters
🌍 Real World
This pattern is used in blogs, news sites, and e-commerce where content updates need to show quickly without rebuilding the entire site.
💼 Career
Understanding revalidation after mutation is key for Next.js developers to build fast, dynamic sites with static generation benefits.
Progress0 / 4 steps