MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
Deferred Data and Suspense Streaming with Await0%
Study Materials
React.js for AdvancedProgress 0%
1.1Control Props and Inversion of Control Pattern1.2State Reducer Pattern in Advanced React1.3Prop Getters and Flexible Design Systems1.4Headless UI Architecture and Accessibility Primitives
4.1React Router v6 Data Loaders and Actions4.2Deferred Data and Suspense Streaming with Await4.3Protected Routes and Role-Based Access Guards4.4Scroll Restoration and Optimistic Route Transitions
HomeTutorialsReact.js for AdvancedDeferred Data and Suspense Streaming with Await
Protected Routes and Role-Based Access Guards

Deferred Data and Suspense Streaming with Await

Beginner12 min read•Updated: 2026-11-18•By Er. Sumit Kumar (MSK Institute)
Study MaterialsCheatsheet

1. The Slow Loader Bottleneck

While Data Loaders eliminate render waterfalls, they introduce a potential drawback:

A route will NOT render until ALL data inside its loader function has finished resolving.

Consider a course page:

  • Fast Data (Critical): Course Title, Instructor, Description (Resolves in 80ms).
  • Slow Data (Non-Critical): 500 Student Reviews & Discussion Threads (Resolves in 1800ms).

If you await both queries in the loader:

1// ❌ BAD: Blocks the ENTIRE page transition for 1.8 seconds!
2export async function loader({ params }) {
3 const course = await fetchCourse(params.id); // 80ms
4 const reviews = await fetchReviews(params.id); // 1800ms (Slow!)
5 return { course, reviews };
6}

The user clicks a course link and sits waiting for 1.8 seconds while the screen does nothing!

2. The Solution: Deferred Data with defer

React Router provides defer() (or streaming promises in modern versions).

You await the critical fast data, but do NOT await the slow data. You pass the unresolved Promise directly into the response:

1// src/pages/CourseDetail.jsx
2import { defer } from 'react-router-dom';
3 
4export function courseDetailLoader({ params }) {
5 // 1. Await critical fast data (Page will transition in 80ms!)
6 const coursePromise = fetchCourse(params.id);
7 
8 // 2. Do NOT await slow data!
9 const reviewsPromise = fetchReviews(params.id);
10 
11 return defer({
12 course: await coursePromise, // Resolved synchronously
13 reviews: reviewsPromise // Unresolved Promise streamed to client!
14 });
15}

3. Rendering Deferred Data with <Suspense> and <Await>

In your component:

  • The critical data renders instantly.
  • The slow data is wrapped inside React's <Suspense> and React Router's <Await> component, showing a fallback skeleton while the promise resolves in the background!
1import React, { Suspense } from 'react';
2import { useLoaderData, Await } from 'react-router-dom';
3 
4export default function CourseDetail() {
5 const { course, reviews } = useLoaderData();
6 
7 return (
8 <div className="course-page">
9 {/* 1. Fast data renders immediately! Zero delay! */}
10 <header>
11 <h1>{course.title}</h1>
12 <p>{course.description}</p>
13 </header>
14 
15 {/* 2. Slow data streams in asynchronously without blocking page transition */}
16 <section className="reviews-section">
17 <h3>Student Discussion & Feedback</h3>
18 
19 <Suspense fallback={<div className="skeleton-loader">Loading 500 reviews...</div>}>
20 <Await
21 resolve={reviews}
22 errorElement={<p className="text-red">Failed to load reviews.</p>}
23 >
24 {(resolvedReviews) => (
25 <ul className="reviews-list">
26 {resolvedReviews.map(r => (
27 <li key={r.id}>
28 <strong>{r.author}:</strong> {r.comment}
29 </li>
30 ))}
31 </ul>
32 )}
33 </Await>
34 </Suspense>
35 </section>
36 </div>
37 );
38}

4. Why This Architecture Delivers World-Class UX

  1. 1
    Perceived Performance: The page navigates in 80ms, delivering instant feedback to the user.
  2. 2
    Progressive Rendering: Fast content is readable immediately while secondary sections stream into place.
  3. 3
    Resilient Error Isolation: If the slow reviews API fails, the <Await errorElement={...}> displays a localized error without breaking the main course view!

Interactive Quiz• Knowledge Check

Practice Quiz

Question 1
What problem does deferring data resolve in React Router?
Question 2
What two components are used together in JSX to render deferred promises?
Question 3
What should you pass to resolve={...} on the <Await> component?
Question 4
If the deferred promise rejects with an error, what component handles the error UI?
Question 5
In the loader, which data should be awaited and which data should be deferred?
Next Lesson

Protected Routes and Role-Based Access Guards

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
React Router v6 Data Loaders and ActionsProtected Routes and Role-Based Access Guards

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

Mentor-Led Practical Training

Master React.js for Advanced with Hands-On Projects

Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.

View Full CourseBook Free Demo
PreviousNext
PreviousPrevNext