# `<Suspense>`

> The `<Suspense>` component is used to handle loading states in components that are dynamically imported or rely on asynchronous operations.

## How do I show a loading state with Suspense in React?

The component that delays rendering part of the component tree until some condition is met, such as data loading or code splitting. It helps manage asynchronous operations and loading states.

- Topic: Components
- Type: component

## Example

Wrong:

```jsx
function Page({ commentsPromise }) {
  const comments = use(commentsPromise);
  return <Comments items={comments} />;
}
```

Right:

```jsx
function Page({ commentsPromise }) {
  return (
    <Suspense fallback={<Spinner />}>
      <Comments promise={commentsPromise} />
    </Suspense>
  );
}
```

The component that suspends must be inside the boundary, so the fallback shows while only that part waits for data.

## Common mistakes

- Wrapping a component that fetches in `useEffect` and never seeing the fallback.
- The whole page flashing a spinner on every navigation.

## Key points

- Data that suspends comes from `use()`, `lazy()` or a Suspense-enabled framework, not from `fetch` inside `useEffect`.
- Each `<Suspense>` boundary is placed around a meaningful UI section, not around the whole app only.
- An error boundary sits near the `<Suspense>` boundary to handle rejected promises.
- Updates that should keep old content visible are wrapped in `startTransition` instead of showing the fallback again.

## Interview questions

### Does Suspense work with fetch in useEffect?

No. Suspense only reacts to sources that suspend during render, such as `use()` with a promise, `lazy()` or framework data loaders.

### How do I stop Suspense from showing the fallback again?

Wrap the update that triggers loading in `startTransition`, and React keeps the old content visible while new data loads.

### Does Suspense work with server rendering?

Yes. With streaming server rendering, the fallback is sent first and the content streams in when its data is ready.

## Related cards

- [use()](https://wonderium.dev/react/use.md)
- [lazy()](https://wonderium.dev/react/lazy.md)
- [startTransition()](https://wonderium.dev/react/start-transition.md)
- [Server Components](https://wonderium.dev/react/server-components.md)
- [Streaming SSR](https://wonderium.dev/web/streaming-ssr.md)

---

- Level: [React](https://wonderium.dev/react.md)
- HTML version: https://wonderium.dev/react/suspense
- Last updated: 2026-11-25
