Skip to content
Back to skills

React Container Presentational

ASecurity

> Separate data-fetching containers from stateless presentational components

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

Works with

  • cli
  • api

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-container-presentational --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of React Container Presentational?

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

Security grade badge for React Container Presentational
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/intense-visions-react-container-presentational/badge)](https://www.skillsdirectory.com/skills/intense-visions-react-container-presentational)

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 Container/Presentational Pattern

> Separate data-fetching containers from stateless presentational components

## When to Use

- A component mixes data-fetching logic with rendering, making it hard to test
- You want to reuse the same UI with different data sources
- You are building a component library where UI and data concerns must be independent
- You need to mock data easily in Storybook or unit tests

## Instructions

1. Split the component in two:
   - **Container** (`<Name>Container`): fetches or manages data, passes it as props to the presentational component
   - **Presentational** (`<Name>`): receives data as props, renders UI, has no data-fetching logic
2. The presentational component is a pure function of its props — no `useEffect`, no fetch calls.
3. The container handles loading states, errors, and side effects.
4. Test the presentational component in isolation by passing mock props.

```typescript
// Presentational — pure, testable, no data concerns
interface DogImageProps { imageUrl: string | null; loading: boolean }
function DogImage({ imageUrl, loading }: DogImageProps) {
  if (loading) return <p>Loading...</p>;
  return imageUrl ? <img src={imageUrl} alt="dog" /> : null;
}

// Container — data concern only
function DogImageContainer() {
  const [imageUrl, setImageUrl] = useState<string | null>(null);
  const [loading, setLoading] = useState(true);
  useEffect(() => {
    fetch('https://dog.ceo/api/breeds/image/random')
      .then((r) => r.json())
      .then((d) => { setImageUrl(d.message); setLoading(false); });
  }, []);
  return <DogImage imageUrl={imageUrl} loading={loading} />;
}
```

## Details

This pattern predates hooks but remains valid. With hooks, the "container" logic is often extracted into a custom hook (`useDogImage`) instead of a wrapper component, which achieves the same separation with less nesting.

**Modern equivalent:** Extract data logic into a custom hook, use the hook in the component:

```typescript
function DogImage() {
  const { imageUrl, loading } = useDogImage(); // hook is the "container"
  if (loading) return <p>Loading...</p>;
  return imageUrl ? <img src={imageUrl} alt="dog" /> : null;
}
```

**With React Server Components:** The server/client split supersedes this pattern for many cases — server components handle data fetching, client components handle interactivity.

## Source

https://patterns.dev/react/presentational-container-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.md3 KB
  • skill.yaml706 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.