الانتقال إلى المحتوى
FrontendReact· 7 دقائق للقراءة

Suspense Doesn't Wait for Your useEffect: Loading Data with use() Done Right

Suspense only sees components that suspend while rendering, and use() only works when it gets the same Promise on every render.

ReadIn

مقال كل يوم يفرق معاك

22 نوفمبر 2026
  • كاتب موثّق
  • React 19
محتويات المقال

A product page wraps <ProductDetails> in <Suspense fallback={<Spinner />}>, yet the spinner never appears. The details render at once with "No product", then fill in a moment later. Someone reads that React 19 lets components read Promises, and swaps the Effect for use(fetchProduct(id)). Now the spinner appears and never goes away, the network tab shows the same request again and again, and the console warns: "A component was suspended by an uncached promise". Both versions assumed Suspense waits for whatever data the component loads.

The common misconception

The belief: wrap a component in <Suspense> and the fallback shows while any of its data loads, whether the request starts in an Effect or right in the component body.

The reference's own one-line summary invites it: Suspense "lets you display a fallback until its children have finished loading", and "loading" sounds like any loading at all. use accepts any Promise, so passing it a fresh fetch looks like the natural way to call it. The half that's true: Suspense really can wait for data. But it can't watch your network requests. It reacts to one specific signal: a component that suspends while React is rendering it.

What actually happens

Suspense only sees what suspends during render

A activates when something below it isn't ready while React renders it. The documented cases include code loaded with lazy, a Promise read with use (including data streamed from or loaded through a Suspense-enabled framework) and stylesheets rendered with a precedence prop. Anything that happens after rendering is invisible to it.

An is exactly that. React runs it after the component has rendered and committed, so by the time the fetch starts, the boundary has already shown its content. The <Suspense> docs say it plainly: Suspense doesn't detect data fetched inside an Effect or event handler. The component below is fully rendered, with empty data, and the boundary has nothing to wait for:

TSX ProductDetails.tsx
import { useEffect, useState } from "react";// Wrapped in <Suspense>, yet the fallback never showsexport function ProductDetails({ id }: { id: string }) {  const [product, setProduct] = useState<Product | null>(null);  useEffect(() => {    fetchProduct(id).then(setProduct); // starts after render  }, [id]);  return <h2>{product?.name ?? "No product"}</h2>;}

An Effect that fetches still needs its own loading state, and the cleanup from the race-condition article earlier in this path. The boundary around it is decoration.

use() needs the same Promise on every render

When use receives a pending Promise, the component suspends and React shows the fallback. React doesn't keep any state for a render that suspended before it ever mounted; when the Promise settles, it retries that render from scratch. If the component created the Promise during render, the retry creates a brand-new one, which is pending again, so the component suspends again. React's use docs warn that a Promise created directly in render makes React display the fallback on every re-render, and prevents content from appearing.

TSX ProductPage.tsx
import { Suspense, use } from "react";function ProductDetails({ id }: { id: string }) {  // A new Promise on every render, so every retry suspends again  const product = use(fetchProduct(id));  return <h2>{product.name}</h2>;}export function ProductPage({ id }: { id: string }) {  return (    <Suspense fallback={<p>Loading…</p>}>      <ProductDetails id={id} />    </Suspense>  );}

With the cache, the retry gets the same Promise, and since it has already resolved, use reads the value without suspending. This module-level Map is the minimal version from React's docs; it never evicts or refreshes anything. In a real app the cache usually comes from your framework or data library: the docs describe a Suspense-enabled framework as one that keeps a cache of Promises and calls use to suspend on them.

Create Promises before rendering

The docs' preferred shape is to create the Promise before render, in an event handler, a route loader or a Server Component, and pass it to the component that calls use. Fetching lazily during render delays the request until that component renders and can create waterfalls. A Server Component can even start a request without awaiting it and hand the Promise to a Client Component as a prop: only the part of the page that reads it waits, inside its own boundary, while the rest renders.

Where the data loadsDoes the boundary show its fallback?What to know
fetch in useEffectNo, the component renders at onceLoading state and cleanup are on you
use(fetch(...)) in renderYes, and again after every retryA new Promise per render; content may never appear
use() with a cached PromiseYes, until it settlesLater renders read the value without suspending
Promise from a handler, loader or Server ComponentYes, where it's readThe request starts before render, no waterfall

How to apply it in your project

  1. Check what each boundary waits forFor every <Suspense>, look at the data its children load. If it's fetched in Effects, the boundary never activates: move the reading to use or remove the boundary.
  2. Find Promises created in renderSearch for use( calls whose argument is built on the spot: fetch(...), an async call, or a .then() chain.
  3. Give each Promise one ownerRead it from a cache keyed by the request, from your framework or data library, or create it in an event handler, loader or Server Component and pass it down.
  4. Wrap refetches in a TransitionUse startTransition for refreshes and navigation, so visible content stays on screen while new data loads.

Key takeaways

  • Suspense reacts only to components that suspend during render, like use on a pending Promise or lazy.
  • A fetch in an Effect or event handler is invisible to Suspense; that component renders immediately with no data.
  • use needs the same Promise across renders: create it before render or read it from a cache, never inline.
  • Refetch inside a Transition so a boundary that already shows content doesn't flip back to its fallback.

📚 المصادر

  1. <Suspense> — React API Reference
  2. use — React API Reference
  3. Server Components — React Reference

التعليقات (0)