import Event Types from React (TypeScript)
It's works fine for me:
handleKeyPress (event: React.KeyboardEvent): any {
}
And I use material-ui too
Add KeyboardEvent
to your react import statement. Then, in your handler you can use the KeyboardEvent type. If you don't specify it in the import statement, you will use ES5 declaration of KeyBoardEvent, which won't compile with your react project.
import React, { Component, KeyboardEvent } from "react";
export class MyInput extends Component{
...
handleKeyDown(e: KeyboardEvent<HTMLInputElement>) {
console.log(e);
// Do something here
}
render() {
return (
<input onKeyDown={this.handleKeyDown.bind(this}/>
);
}
}
}