Intermediatenote 02 of 1103 reasons · 03 notes
Next.jsIntermediate
Use generateStaticParams for dynamic routes
Pre-render dynamic pages at build time instead of on every request to cut TTFB.
Code example
Copy, adapt, and ship.
Read the numbered lines, copy the complete snippet, then adjust the values for your project.
// app/blog/[slug]/page.jsxexport async function generateStaticParams() { const posts = await getPosts(); return posts.map((post) => ({ slug: post.slug, }));} export default async function BlogPost({ params }) { const post = await getPostBySlug(params.slug); return <Article post={post} />;}Why this matters
The production reason.
- 01
Dynamic routes are flexible, but if every slug waits for a server request before rendering, your first byte gets slower and crawlers see less stable output.
- 02
Use generateStaticParams when you already know the important slugs at build time: blog posts, product pages, docs, landing pages, and category archives.
- 03
Keep this paired with a sensible fallback strategy for content that changes often, so new pages can still appear without a full rebuild when your app needs that behavior.
How it holds up outside a demo.
- Next.jsUse this in App Router dynamic segments like app/blog/[slug]/page.jsx.
- Sanity or CMSQuery only slug fields here, not the full document body.
- VercelPair with revalidate or webhook-triggered deploys for fresh editorial content.
Explore other stacks
Jump into a different technology.
11 Next.js notes on this shelf, and six more stacks beside it.
Keep state close to the interaction
Local state avoids unnecessary parent renders and keeps component intent obvious.
Open the noteAbort stale fetch requests
Cancel outdated browser requests so fast UI changes do not render old data.
Open the noteBuild a CSS gradient generator with code export
A CSS gradient generator should preview color stops, preserve accessible contrast, and export clean CSS code.
Open the noteFix WordPress H1 SEO issues
Fix WordPress SEO issues by keeping one clear H1, escaping template output, and compressing images before WordPress upload.
Open the noteReduce LCP with image optimization
Reduce LCP with image optimization by resizing, converting, and compressing images before they reach production.
Open the noteUse real buttons for actions
If it changes state, use button. If it navigates, use a link.
Open the note