https://nextjs.org/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating

https://nextjs.org/docs/app/building-your-application/data-fetching/server-actions-and-mutations

https://nextjs.org/docs/app/building-your-application/data-fetching/patterns

App router 기준 Next.js에서 data fetching을 요약하자면 다음과 같다.

Data Fetching, Caching and Revalidating

Data fetching is a core part of any application. This page goes through how you can fetch, cache, and revalidate data in React and Next.js.

There are four ways you can fetch data:

  1. On the server, with fetch
  2. On the server, with third-party libraries
  3. On the client, via a Route Handler
  4. On the client, with third-party libraries. (e.g. SWR, TanStack Query)

Server Actions and Mutations

Patterns and Best Practices

Fetching data on the server

Next.js는 가능할때면 언제나 Server Component에서 데이터 페칭을 하는 것을 권장한다고 한다(물론 필요할때는 Client Component를 적절히 활용해야 겠지만). 이는 다음과 같은 장점들이 있다.