Full answer
The idea is simple. Instead of a component rendering fixed markup, it receives a function and calls it with data: <MouseTracker render={(pos) => <p>{pos.x}</p>} />. The children prop can carry the function too, which is called function as children.
This pattern solved logic sharing for class components. The tracking logic lives in one component. The caller decides how to display the numbers. It is explicit about where data comes from, unlike a HOC, but it can create "callback pyramids" when several render props are nested.
A custom hook gives the same logic without any wrapper: const pos = useMousePosition(). For logic-only sharing, prefer the hook.
Render props are still good when the component must call your function many times or at specific places in its own structure. A list that renders each row, a virtualized list, a table cell renderer, a form library field wrapper (<Field>{({ value, onChange }) => ...}</Field>), and headless components such as dropdown or combobox primitives all fit. The component owns the structure and behaviour, and the caller owns what each part looks like.
Keep the function cheap and stable where it matters. A new inline function on every render defeats memo on the component receiving it. Give the render function a clear argument object that is easy to extend.
The example implements a counter with a render prop and the hook form side by side.
import { useState } from 'react';
function Counter({ initial = 0, children }) {
const [count, setCount] = useState(initial);
return children({ count, increment: () => setCount((c) => c + 1) });
}
function useCounter(initial = 0) {
const [count, setCount] = useState(initial);
return { count, increment: () => setCount((c) => c + 1) };
}
function HookVersion() {
const { count, increment } = useCounter(10);
return <button onClick={increment}>Hook: {count}</button>;
}
export default function App() {
return (
<div>
<Counter>
{({ count, increment }) => <button onClick={increment}>Render prop: {count}</button>}
</Counter>
<HookVersion />
</div>
);
}Both buttons share the same logic. The first uses a function as children and the second a custom hook. The check pressed each button once. Rendered result: <div><button>Render prop: 1</button><button>Hook: 11</button></div>
Key points
- A render prop is a function prop the component calls to render part of its output.
- It shares logic while the caller controls markup. Hooks now cover logic-only sharing.
- Deep nesting of render props is hard to read.
- It still suits lists, rows, cell renderers and headless UI parts.
- Inline render functions create new references and can defeat memo.
Common mistakes
- Using render props for logic that a hook shares more simply.
- Nesting several render props, which creates a callback pyramid.
- Passing a new inline function to a memoized component and defeating memo.
- Calling the render function with inconsistent arguments between renders.
Follow-ups
- How would you convert the Counter to a custom hook, and what would you lose?
- Where have you seen function-as-children in popular libraries?
- How do render props compare with compound components?
Tips
- Show the same logic as a hook. It proves you understand why the pattern faded.
- Name the cases where it still wins.
- Use the term "function as children" so interviewers see you know both spellings.