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
You have to take it in through the props in
CustomImage
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?yup, that looks good
thanks heaps