liveBook · Manning

Fallback

As explained in React Hooks in Action: With Suspense and Concurrent Mode

A fallback is alternate user-interface content displayed while the intended content is unavailable or an error has occurred.

A fallback is alternate UI shown while intended content is unavailable. In React, it keeps a slow-loading calendar, message, or image from leaving an empty region. section 11.2.2 section 12.3

Use Suspense to declare loading content for lazy descendants. Its fallback replaces the children until they return UI; once loaded, the intended content replaces the fallback. section 11.2.2

Choose the boundary and fallback according to the failure or delay:

  • Wrap lazy UI in Suspense and set fallback to concise placeholder content such as “Loading...”. section 11.2.2
  • Give separate Suspense boundaries to independent regions when one loading component should not replace another region’s UI. section 11.2.2
  • Place an ErrorBoundary around UI that may throw, and provide recovery guidance such as “Try reloading the page.” section 11.3.2
  • Combine ErrorBoundary and Suspense when loading can either remain pending or fail: show a loading fallback first and an error fallback on rejection. section 12.1

Loading and error states

Use nested boundaries to distinguish pending data from failure: <ErrorBoundary fallback="Oops!"><Suspense fallback="Loading message..."><Message /></Suspense></ErrorBoundary>. Message retrieves data or throws a promise or error; React then selects the appropriate fallback. section 12.1

<Suspense fallback={<div>Loading...</div>}>
 <CalendarWrapper />
</Suspense>

Inspect the minimal Suspense pattern: a fallback prop supplies placeholder UI while the lazy descendant loads. section 11.2.2

How React Hooks in Action: With Suspense and Concurrent Mode covers it

How deep it goes
Explains boundary selection, replacement behavior, and custom error handling, but treats data fetching through Suspense as experimental.
Examples
Uses loading calendars, messages, user avatars, and customizable error screens with reload instructions.
What it assumes
Assumes React components and JSX, while demonstrating the boundary behavior needed for delayed or failed UI.
What you can do after
Build and configure loading and error states with Suspense, fallback props, and ErrorBoundary components.
How it connects
Connects Suspense with lazy loading, dynamic imports, error boundaries, promises, data fetching, and React Query.

Also explained in

Compare how 15 books explain fallback →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of React Hooks in Action: With Suspense and Concurrent Mode. The section links point to the parts of the book it draws on.