I have a react functional component and I want to decide dynamically if I want to have an onClick handler on it, something like this:
const foo () => {
let add_onClick = true;
return (
<div *(if add_onClick ==true then add an onClick event)*/>
)
}
I think I can convert the component to a class, create a Ref for the component then add a click eventListener in componentDidMount, but is there a simpler way to do this?