
| Strategy: Click for details | Location | When it runs | Advantages | Disadvantages |
|---|---|---|---|---|
| Fetch in server components | app/page.tsx, app/layout.tsx, etc. | Before HTML generation | Fast loading and good SEO | Unsuitable for dynamic interactions |
| Client component + useEffect | A 'use client' component | After mounting | Can fetch after user interactions | Initial loading may be slower |
| SWR or React Query | Client component | After mounting, with caching | Automates caching, revalidation, and refetching | May increase bundle size |
| Route handler: API | app/api/** | When a separate server API is needed | Can provide backend functionality | Requires additional configuration |
| ISR: revalidate | Server component | Cache plus regeneration | Improves data freshness | Keeps cached data during the configured interval |
| no-store | Server component | Always fresh data | Fetches anew on each request | Higher performance cost |
revalidate if necessary.fetch('https://api.example.com/docs', {
next: { revalidate: 3600 }, // 1์๊ฐ๋ง๋ค ๊ฐฑ์
});const cookieStore = cookies();
const token = cookieStore.get('auth');
await fetch('https://api.example.com/user', {
headers: { Authorization: `Bearer ${token?.value}` },
});'use client';
const { data, mutate } = useSWR('/api/posts', fetcher);
// ์ฌ์ฉ์ ์ก์
ํ mutate()cache: 'no-store'.await fetch('https://api.example.com/status', { cache: 'no-store' });fetch, caching strategies, SWR, route handlers, and cache invalidation.
We covered most of the situations needed in real projects.
Next.js data fetching is closely connected to React, so understanding