I have a React function component, where I get another component in props. Something like this:
function ChildComponent({cmp}) {
// Here onClick handlers should be added [for example:
// () => console.log("clicked")] to all
// elements in cmp of class .clickable
return ...
}
function ParentComponent() {
return (
<ChildComponent cmp={<div><button>Non-clickable</button><button className="clickable">Clickable</button></div>} />
)
}
So how to add event handlers dynamically to elements with class clickable in the cmp props variable in the ChildComponent? Thank you in advance for your help.