Tsallaka zuwa abun ciki
Justice Tech School

Render Props

Pass a function as a prop to share rendering logic.

Example
function Mouse({ render }) {
  const [p, setP] = useState({ x: 0, y: 0 });
  return <div onMouseMove={(e) => setP({ x: e.clientX, y: e.clientY })}>{render(p)}</div>;
}
<Mouse render={(p) => <b>{p.x}</b>} />;

Exercise

Prop is a function.

render={(p)  <b>{p.x}</b>}

Quiz Test

What is a render prop?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.