My App component passes down an event handler as a prop to a Button Component
// App.js
public handlePlay = () => {
this.setState({ ****** })
}
// render
<Button play={this.handlePlay} />
What is the correct type for the event handler passed via prop i.e. play
?
// Button.js
interface ButtontProps {
play: any //what is the correct type here?
}
export const Button: React.SFC<ButtontProps> = ({ play }) => (
<button onClick={play}>Play</button>
)
I don't want to use any
as that would divert me from applying the correct types for such an instance.
It should most likely be either of the following
(event: React.MouseEvent<HTMLElement>) => void
(event: React.MouseEvent<HTMLInputElement>) => void
You can confirm this by looking at the React typings over here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With