Question presented to candidate: "What is the render props pattern, what problem did it solve, and do you still use it?"
What a strong answer should cover:
- A render prop is a prop whose value is a function returning UI. The component owns some state or behaviour and calls that function with it, letting the caller decide the markup.
childrenas a function is the same pattern with a different prop name.- The problem it solved: sharing stateful logic before Hooks existed, without the wrapper-component drawbacks of HOCs.
- Key advantage over HOCs: composition happens at render time, so it can use values from the surrounding render, and there are no prop-name collisions or lost statics.
- The costs: nesting ("callback hell" in JSX) when several are combined, and an inline function is a new identity every render, which defeats
React.memoon the receiving component. - Custom Hooks replaced it for pure logic sharing — no nesting, no identity problem.
- Where it survives legitimately: when the component must control rendering, not just supply data — virtualised lists, headless UI components, data tables, and libraries that need to own the loop.
Clarifying questions expected:
- "Is the shared thing logic, or does the component need to control the rendering?" — that decides Hook versus render prop.
Code / implementation expected: Yes — a render prop component, ideally with the Hook equivalent beside it.