Binding to component onClick

Hi, I am trying to bind to the onClick property of a custom component. I understand this is doable for a regular HTML element such as a button but how can I achieve the same for a custom component? e.g. <CustomImage onClick={handleMouseClick} /> ?
4 Replies
REEEEE
REEEEE7mo ago
You have to take it in through the props in CustomImage
function CustomImage(props){

return <div onClick={props.onClick} />
}
function CustomImage(props){

return <div onClick={props.onClick} />
}
Barbara88
Barbara88OP7mo ago
Thanks! I am passing down a function from the parent component now, the prop has the type clickFunc: () => void and binding to it using onClick={props.clickFunc} in the child function. Just wanted to check that is the best way to do it?
REEEEE
REEEEE7mo ago
yup, that looks good
Barbara88
Barbara88OP7mo ago
thanks heaps
Want results from more Discord servers?
Add your server