Hint
Pass a function as a prop that returns JSX — the component calls it with its internal state
// Render props — component shares state by calling a function prop
function MouseTracker({ render }) {
const [pos, setPos] = useState({ x: 0, y: 0 });
return (
setPos({ x: e.clientX, y: e.clientY })}>
{render(pos)} {/* caller decides what to render */}
);
}
// Usage
(
Mouse at {x}, {y}
)} />
// children as a function (same pattern)
{({ x, y }) => }
Render props vs custom hooks: