typescriptintermediate
Streaming with Loading UI and Suspense
Use loading.tsx and React Suspense to stream UI progressively in Next.js App Router.
typescriptPress ⌘/Ctrl + Shift + C to copy
// app/dashboard/loading.tsx
export default function DashboardLoading() {
return (
<div className="animate-pulse space-y-4">
<div className="h-8 bg-gray-200 rounded w-1/3" />
<div className="grid grid-cols-3 gap-4">
{[...Array(3)].map((_, i) => (
<div key={i} className="h-32 bg-gray-200 rounded" />
))}
</div>
</div>
);
}
// app/dashboard/page.tsx
import { Suspense } from 'react';
async function SlowChart() {
const data = await fetch('https://api.example.com/chart-data', {
cache: 'no-store',
}).then((r) => r.json());
return <Chart data={data} />;
}
async function QuickStats() {
const stats = await fetch('https://api.example.com/stats', {
next: { revalidate: 60 },
}).then((r) => r.json());
return <StatsCards stats={stats} />;
}
export default function DashboardPage() {
return (
<div>
<h1>Dashboard</h1>
<Suspense fallback={<StatsSkeleton />}>
<QuickStats />
</Suspense>
<Suspense fallback={<ChartSkeleton />}>
<SlowChart />
</Suspense>
</div>
);
}Use Cases
- dashboards
- progressive loading
- improving perceived performance
Tags
Related Snippets
Similar patterns you can reuse in the same workflow.
typescriptintermediate
Next.js Streaming with Suspense
Stream server components with Suspense boundaries for progressive page loading and better TTFB.
Best for: Progressive loading for data-heavy dashboards
#nextjs#streaming
typescriptbeginner
Loading UI with Skeleton Screens
Create loading.tsx skeleton screens for instant navigation feedback with Next.js App Router.
Best for: Route transition loading states
#nextjs#loading
typescriptadvanced
Partial Prerendering with Suspense
Combine static shells with streamed dynamic content using React Suspense for instant page loads.
Best for: E-commerce product pages
#ppr#suspense
typescriptbeginner
Custom Not Found Page
Create a custom not-found.tsx with search suggestions, popular links, and a return home button.
Best for: Custom 404 error pages
#nextjs#error