I have the following code for a React component. What's the right way to declare the two onClick
handlers passed into the component?
interface LoginFormProps {
loginClicked: ???? <--- onClick handler signature
cancelClicked: ???? <--- onClick handler signature
}
class LoginForm extends React.Component<LoginFormProps, {}> {
render() {
<form>
<button onClick={loginClicked}>
Login
</button>
<button onClick={cancelClicked}>
Cancel
</button>
</form>
}
}
I typically use:
interface ILoginFormProps {
loginClicked: (ev) => void;
//
}
But if you want to be really strict about your typing:
interface ILoginFormProps {
loginClicked: (ev: React.MouseEvent<HTMLButtonElement>) => void;
//
}
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