Advertisement
Beginner Next.js, Loading UI & Streaming with Suspense

How do you show a loading state automatically while a page's data is being fetched in the App Router?

Short answer

You add a file named loading.js inside the same route folder as your page, and Next.js automatically displays it while the page's server component is fetching data, giving users instant visual feedback instead of a blank screen while they wait.

Save Next.js mock interview
Advertisement
AModel answer
You add a file named loading.js inside the same route folder as your page, and Next.js automatically displays it while the page's server component is fetching data, giving users instant visual feedback instead of a blank screen while they wait.
// app/dashboard/loading.js
export default function Loading() {
  return <p>Loading dashboard...</p>;
}
Real-world example
A dashboard shows a friendly loading spinner immediately while it fetches the user's data in the background, giving instant feedback instead of leaving the screen blank.
Likely follow-ups
  • How does loading.js relate to React Suspense under the hood?
  • Can you customize the loading indicator with a skeleton screen instead of plain text?
Related topics