Skip to content
Back to skills

React Suspense Pattern

ASecurity

> Declaratively handle async loading states with React Suspense boundaries

  • 20 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added September 11, 2026
developmenttypescriptreactperformance

Security analysis

A100/100

Pro scans all 2 files and shows the line behind each finding

Scanned September 11, 2026

npx -y skills add Intense-Visions/harness-engineering --skill react-suspense-pattern --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of React Suspense Pattern?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for React Suspense Pattern
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/intense-visions-react-suspense-pattern/badge)](https://www.skillsdirectory.com/skills/intense-visions-react-suspense-pattern)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
# React Suspense Pattern

> Declaratively handle async loading states with React Suspense boundaries

## When to Use

- Lazy-loading components with `React.lazy()` — Suspense is required
- Data fetching with Suspense-enabled libraries (React Query, SWR with suspense option, Relay)
- You want loading states co-located with the UI rather than scattered in `useEffect`
- Building React 18+ applications with concurrent features

## Instructions

1. Wrap any component that may suspend with `<Suspense fallback={<LoadingUI />}>`.
2. Place Suspense boundaries at the granularity you want loading states — one per page, per section, or per widget.
3. Always pair Suspense boundaries with `<ErrorBoundary>` to handle promise rejections.
4. For lazy imports, use `React.lazy(() => import('./Component'))`.
5. Do not put Suspense boundaries inside loops — create a reusable wrapper component instead.

```typescript
const HeavyChart = React.lazy(() => import('./HeavyChart'));

function Dashboard() {
  return (
    <ErrorBoundary fallback={<p>Failed to load chart</p>}>
      <Suspense fallback={<ChartSkeleton />}>
        <HeavyChart />
      </Suspense>
    </ErrorBoundary>
  );
}
```

## Details

Suspense works by components "throwing" a promise when they are not ready. React catches the promise at the nearest Suspense boundary and renders the fallback until the promise resolves.

**React 18 changes:** `startTransition` lets you mark state updates as non-urgent, preventing Suspense fallbacks from showing for fast transitions (the previous content stays visible until the new content is ready).

**Library support:** Not all data-fetching approaches support Suspense. Use libraries that explicitly support it (`useSuspenseQuery` in React Query, `use()` hook in React 18+ with compatible data sources).

**Common mistake:** Placing the Suspense boundary too high (at the page level) shows a full-page spinner for small widget loads. Granular boundaries improve perceived performance.

## Source

https://patterns.dev/react/suspense-pattern

## Process

1. Read the instructions and examples in this document.
2. Apply the patterns to your implementation, adapting to your specific context.
3. Verify your implementation against the details and edge cases listed above.

## Harness Integration

- **Type:** knowledge — this skill is a reference document, not a procedural workflow.
- **No tools or state** — consumed as context by other skills and agents.

## Success Criteria

- The patterns described in this document are applied correctly in the implementation.
- Edge cases and anti-patterns listed in this document are avoided.

Files in this skill

  • SKILL.md2.6 KB
  • skill.yaml710 B

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.