Skip to content

Render Props

In one line

Render props is a pattern where a component takes a function as a prop and calls it to determine what to render — a way to share rendering logic.

In simple words

The render props pattern uses a function prop to share code between components. The component with the logic calls the function prop, passing it data, and the function returns JSX.

<MouseTracker render={(mouse) => <Cat position={mouse} />} /> — MouseTracker tracks the mouse position and calls the render prop with the current position. The parent decides what to render with that data.

Like HOCs, render props were a pre-Hooks pattern for sharing stateful logic. Today, custom Hooks are preferred — they are simpler and don't require wrapper components or function props. But render props are still useful when the logic is inherently about rendering (like animation libraries).

Example

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

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

MouseTracker manages the mouse position and calls the render prop with it. The caller decides what to display.

Related terms

Related Resources

Related Lessons

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors

← Back to glossary