import Event Types from React (TypeScript)


How to import Event Types from React?

For an example how to import KeyboardEvent so it can be used for onKeyDown callback type annotation?

I have browsed Material-ui .d.ts file and found that in that file EventTypes are used as defined in React

onKeyDown?: React.KeyboardEventHandler;

And in React .d.ts

type KeyboardEventHandler = EventHandler<KeyboardEvent>;

But I can’t find a way to use import them …


It’s works fine for me:

handleKeyPress (event: React.KeyboardEvent): any {

And I use material-ui too

Answered By – Ser

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published