Frameworks & Libraries
Next.js & Remix
Meta-frameworks that supercharge React with server-side rendering, file-based routing, and full-stack data patterns. Next.js offers fine-grained caching and Server Components; Remix champions web-native forms and nested route data loading.
What is Next.js?
Next.js is a React framework that adds file-based routing, server rendering, static generation, API routes and image and font optimisation. Pages render on the server, so users and search engines get real HTML immediately, then React takes over in the browser. Remix (now part of React Router) offers a similar full-stack model built around web standards.
// app/blog/[slug]/page.tsx (Next.js App Router)
export default async function Post({ params }) {
const { slug } = await params;
const post = await getPost(slug); // runs on the server
return <article><h1>{post.title}</h1></article>;
}Server vs Client Components
Server Components (default)
- Can be async — await any data directly
- Zero JavaScript sent to the client
- Access databases, file system, secrets safely
- Can import server-only packages
- Cannot use hooks (useState, useEffect)
- Cannot handle events or use browser APIs
Client Components 'use client'
- Can use all React hooks
- Handle click, input, and other events
- Access browser APIs (window, localStorage)
- Can use third-party client libraries
- JS bundle is sent to the browser
- Cannot be async top-level components
Rendering Modes Comparison
| Mode | When HTML created | Data freshness | Best for |
|---|---|---|---|
| SSG (Static) | Build time | Stale until rebuild | Marketing pages, blogs, docs |
| ISR | Build + revalidate | Configurable (30s–∞) | Product pages, news feeds |
| SSR (Dynamic) | Every request | Always fresh | User dashboards, auth pages |
| CSR (Client) | Browser (JS) | Client-controlled | Highly interactive widgets |
| Streaming SSR | Server, in chunks | Always fresh | Slow data + fast UI skeleton |
Common Pitfalls
Adding 'use client' to everything to avoid Server Component restrictions — destroys SSR benefits
Keep data-fetching in Server Components. Only add 'use client' to interactive leaf components.
Calling fetch() in Client Components inside useEffect — waterfall fetching, slow
Fetch in Server Components (or Remix loaders) so data arrives with the HTML. No client waterfalls.
Not using generateStaticParams() for dynamic routes — entire route becomes dynamic (slow)
Use generateStaticParams() to pre-render known slugs at build time for instant static serving.
Using client-side navigation for auth checks — flashes unauthorized content briefly
Use Next.js middleware.ts or Remix loaders to redirect unauthenticated requests on the server.
Interactive Demo
Code Editor
<p>A Next.js App Router page. It runs on the server, so it isn't runnable here:</p>
<pre>// app/posts/[slug]/page.tsx
export async function generateMetadata({ params }) {
const { slug } = await params;
return { title: `Post: ${slug}` };
}
export default async function PostPage({ params }) {
const { slug } = await params;
const post = await fetch(`https://api.example.com/posts/${slug}`)
.then((r) => r.json()); // fetched on the server
return (
<article>
<h1>{post.title}</h1>
<p>{post.body}</p>
</article>
);
}</pre>
<p>Visiting <code>/posts/hello</code> sends finished HTML to the browser, which is great for SEO.</p>Preview
Next.js and Remix: summary
Key points
- Server Components ship zero JavaScript for parts that don't need interactivity.
- Add
"use client"only to components that need state, effects or browser APIs. - Static generation plus revalidation gives fast pages with fresh data.
Frequently asked questions
›Is Next.js good for SEO?
Yes. Server-rendered or statically generated HTML, the metadata API and fast loading all help search engines index the pages.