JS Guide
HomeQuestionsTopicsCompaniesResources
BookmarksSearch

Built for developers preparing for JavaScript, React & TypeScript interviews.

ResourcesQuestionsSupport
HomeQuestionsSearchProgress
HomeQuestionsreact
PrevNext

Learn the concept

Concurrent React

react
senior
concurrent

What are React's concurrent features and how do Suspense and transitions work?

concurrent
suspense
useTransition
useDeferredValue
performance
lazy
use
activity
Quick Answer

Concurrent React enables interruptible rendering, allowing React to pause low-priority work for urgent updates. Suspense handles async loading states declaratively. useTransition marks updates as non-urgent, and useDeferredValue defers expensive re-renders.

Detailed Explanation

Concurrent Rendering:

  • Rendering is interruptible
  • React can work on multiple versions of UI
  • High-priority updates (typing) interrupt low-priority (search results)
  • Enables smooth UX during complex updates

Suspense:

  • Declarative loading states
  • Shows fallback while children load
  • Works with lazy(), data fetching libraries
  • Allows streaming SSR

useTransition:

  • Marks state update as non-urgent
  • Keeps UI responsive during heavy updates
  • Returns [isPending, startTransition]

useDeferredValue:

  • Defers updating a value until urgent work completes
  • Shows stale data while computing new data
  • Like debouncing but smarter

use() Hook (React 19):

  • Reads promises and context during render
  • Integrates with Suspense for data fetching
  • Can be called conditionally (unlike other hooks)
  • use(promise) — suspends until promise resolves
  • use(context) — preferred over useContext, more flexible

Activity Component (React 19.2):

  • <Activity mode="visible"> — renders children normally
  • <Activity mode="hidden"> — hides children, unmounts effects, defers updates
  • Preserves component state when hidden (unlike unmounting)
  • Pre-render upcoming navigation targets in the background
  • Useful for tab systems, navigation pre-loading

React 19 Actions:

  • useActionState — manages form state with pending/error/result tracking
  • useFormStatus — access form submission status from child components
  • useOptimistic — show optimistic UI while async action completes
  • Form actions use transitions under the hood for non-blocking updates

useEffectEvent (React 19.2):

  • Separates event-like logic from reactive effects
  • Always sees latest props/state without re-running the effect
  • Replaces the common useRef + useEffect pattern for stable callbacks

Code Examples

Suspense for code splittingJSX
import { Suspense, lazy } from 'react';

// Lazy load component
const Dashboard = lazy(() => import('./Dashboard'));
const Settings = lazy(() => import('./Settings'));

function App() {
  const [page, setPage] = useState('dashboard');
  
  return (
    <div>
      <nav>
        <button onClick={() => setPage('dashboard')}>Dashboard</button>
        <button onClick={() => setPage('settings')}>Settings</button>
      </nav>
      
      {/* Suspense shows fallback while lazy component loads */}
      <Suspense fallback={<div>Loading...</div>}>
        {page === 'dashboard' ? <Dashboard /> : <Settings />}
      </Suspense>
    </div>
  );
}

// Nested Suspense for granular loading
function App() {
  return (
    <Suspense fallback={<PageSkeleton />}>
      <Header />
      <Suspense fallback={<SidebarSkeleton />}>
        <Sidebar />
      </Suspense>
      <Suspense fallback={<ContentSkeleton />}>
        <MainContent />
      </Suspense>
    </Suspense>
  );
}

Real-World Applications

Use Cases

Search-as-You-Type

Using useTransition to keep the search input responsive while filtering large datasets in the background

Page Transitions

Using Suspense boundaries with transitions for smooth navigation between data-heavy pages

Pre-Rendering Navigation Targets

Using Activity component to pre-render likely next pages while keeping them hidden

Mini Projects

Concurrent Data Explorer

advanced

Build a data explorer using useTransition for filtering, Suspense for loading, and use() for data fetching

Activity-Based Tab System

advanced

Implement a tab system using Activity component where tab state is preserved when switching between tabs

Industry Examples

Next.js App Router

Built on React Suspense and concurrent features for streaming SSR

Relay

Facebook's GraphQL client deeply integrated with Suspense and concurrent rendering

Resources

React Docs - Suspense

docs

React Docs - useTransition

docs

React Docs - useDeferredValue

docs

Related Questions

Explain React.memo, useMemo, and useCallback. When should each be used?

senior
performance
Previous
How does React's reconciliation algorithm work?
Next
How do Error Boundaries work in React and what are their limitations?
PrevNext