| November 19, 2025 |

Data fetching simply means:
Getting data from somewhere — an API, a database, or a file — so your UI can show real information instead of an empty page.
Examples:
Why it’s important:
Next.js helps with all these because it gives you both server and client data-fetching tools in one framework.
fs, files, paths)This difference is the foundation of data fetching in Next.js.
Next.js adds a mini backend inside your React project.
This means you can fetch data in three places depending on your needs:
Let’s break them down.
Server Components run only on the server, so they can safely:
fs, path, env variables)This code never runs in the browser.
Example:
export default async function Page() {
const res = await fetch(”https://api.vercel.app/blog”);
const posts = await res.json();
return <div>{posts[0].title}</div>;
}Behind the scenes, Next.js:
This makes Server Components ideal for:
Client Components run in the browser.
You use them when the user needs to interact with the UI:
This is also where you’d use SWR or React Query for automatic caching.
Example with SWR:
‘use client’
import useSWR from ‘swr’
const fetcher = (url) => fetch(url).then((res) => res.json())
export default function BlogPage() {
const { data, isLoading } = useSWR(’/api/posts’, fetcher)
return isLoading ? “Loading...” : data[0].title
}Use Client Components when:
useState or useEffectRoute Handlers live in:app/api/.../route.ts
They let you create API endpoints inside your app.
// app/api/posts/route.ts
export async function GET() {
return Response.json({ message: “Hello” })
}Your frontend can call:
fetch(”/api/posts”)
Use this when you need:
React can only fetch in the browser.
Next.js fetches before your page loads.
Extended fetch options:
// always fresh
fetch(url, { cache: “no-store” })
// revalidate every 60 seconds
fetch(url, { next: { revalidate: 60 }})Next.js automatically:
Loading states built into the framework.
Example:
<Suspense fallback={<div>Loading...</div>}>
<Posts />
</Suspense>Next.js can send your page in chunks so the user sees something immediately.
Start multiple requests at the same time:
const artistData = getArtist();
const albumsData = getAlbums();
const [artist, albums] = await Promise.all([artistData, albumsData]);Faster than waiting for one request to finish before starting the next.
useEffectBottom line:
React gives you UI.
Next.js gives you a full-stack environment.
Use this rule:
Fetch data on the server when possible.
Fetch in the client only when interaction is required.
This keeps your app:
Next.js Official Documentation — Data Fetching
Thanks for reading :)