T
T
tron212021-11-24 22:09:55
JavaScript
tron21, 2021-11-24 22:09:55

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

1 answer(s)
Y
Yuriy Vorobyov, 2021-11-25
@timofeus91

Instead of any, you need React.MouseEvent<HTMLElement>or EventTarget. A returnsJSX.Element

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question