Answer the question
In order to leave comments, you need to log in
How to properly create an event function using TypeScript?
Good day to all! There is a code where on clicking the button we output an event to the console. The code works. But I'm interested in what, according to the rules, should be put instead of any . And what should this function return? Just trying to learn TypeScript and how to deal with events properly
const Something : FC = () => {
const justClick = (event: any): void => {
console.log(event);
}
return (
<button className="button" onClick={justClick}>Просто кнопка</button>
)
}
Answer the question
In order to leave comments, you need to log in
Instead of any, you need React.MouseEvent<HTMLElement>
or EventTarget
. A returnsJSX.Element
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question