Skip to content
Back to skills

React Render Props Pattern

ASecurity

> Share stateful logic by passing a render function as a prop

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

Works with

  • cli

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-render-props-pattern --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of React Render Props Pattern?

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

Security grade badge for React Render Props Pattern
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/intense-visions-react-render-props-pattern/badge)](https://www.skillsdirectory.com/skills/intense-visions-react-render-props-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 Render Props Pattern

> Share stateful logic by passing a render function as a prop

## When to Use

- You need to share stateful behavior without coupling the rendering to the logic
- The rendering of the shared state is highly variable between consumers
- You are working with class components (pre-hooks) or third-party components that do not expose hooks
- Building components for library distribution where render control must stay with consumers

## Instructions

1. Create a component that manages the shared state or behavior.
2. Accept a `render` prop (or `children` as a function) that receives the state as arguments.
3. Call the render prop inside the component's return, passing the managed state.
4. Consumers control all rendering; the provider controls only the logic.

```typescript
interface MousePosition { x: number; y: number }

function MouseTracker({ render }: { render: (pos: MousePosition) => React.ReactNode }) {
  const [pos, setPos] = useState<MousePosition>({ x: 0, y: 0 });
  return (
    <div onMouseMove={(e) => setPos({ x: e.clientX, y: e.clientY })}>
      {render(pos)}
    </div>
  );
}

// Usage
<MouseTracker render={({ x, y }) => <p>Mouse at {x}, {y}</p>} />
```

## Details

Render props were the dominant pattern for logic reuse before React hooks. With hooks available, most new render props use cases should be implemented as custom hooks instead. However, render props remain valuable in specific scenarios:

- Third-party library integration where hooks are unavailable
- Highly dynamic rendering decisions that benefit from explicit prop passing
- Class component contexts

**Children as function** is a common variant:

```typescript
<MouseTracker>{({ x, y }) => <p>At {x}, {y}</p>}</MouseTracker>
```

**Trade-offs vs hooks:**

- Render props require wrapping in JSX; hooks are called inline — hooks are almost always simpler
- Render props make the data flow explicit in JSX; hooks hide the data flow in function calls
- Multiple render props create "wrapper hell" (the problem hooks solved)

## Source

https://patterns.dev/react/render-props-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.yaml671 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.