React / Next.js

Next.js Data Fetching

Server-side rendering (SSR), static generation (SSG), incremental static regeneration (ISR), streaming

24 interview questionsยท
Mid-Level
1

What is the default behavior of Server Components in Next.js App Router for data fetching?

Answer

Server Components perform data fetching on the server with each request by default, ensuring fresh data. Unlike Pages Router where getServerSideProps was needed, Server Components make SSR implicit. For static caching, the cache: 'force-cache' option must be added to fetch.

2

Which fetch cache option is equivalent to getStaticProps in Pages Router?

Answer

The cache: 'force-cache' option tells Next.js to cache the response until manually invalidated, equivalent to getStaticProps. This strategy generates static content that remains cached indefinitely. The 'no-store' option equals getServerSideProps (re-fetch every request), while next.revalidate equals getStaticProps with revalidate (ISR).

3

How to force dynamic data fetching on every request (getServerSideProps equivalent)?

Answer

The cache: 'no-store' option completely disables caching and forces re-fetching on every request, equivalent to getServerSideProps. This strategy ensures always fresh data but increases latency. Use for real-time data (dashboards, notifications, live prices) where freshness is critical.

4

How to implement ISR (Incremental Static Regeneration) with hourly revalidation?

5

What does 'export const revalidate = 60' export at page level do?

+21 interview questions

Master React / Next.js for your next interview

Access all questions, flashcards, technical tests, code review exercises and interview simulators.

Start for free