Typescript 2.3.4, react 15.5.4 and react-bootstrap 0.31.0.
I have a FormControl
and I want to do something when the user presses enter.
The control:
<FormControl
name="keyword"
type="text"
value={this.state.keyword}
onKeyPress={this.handleKeywordKeypress}
onChange={(event: FormEvent<FormControlProps>) =>{
this.setState({
keyword: event.currentTarget.value as string
});
}}
/>
What should the definition of the parameter for handleKeywordKeypress
be?
I can define it like this:
handleKeywordKeypress= (e: any) =>{
log.debug("keypress: " + e.nativeEvent.code);
};
That will be called, and it will print kepress: Enter
but what should the type of e
be so that I can compare the value against (what?) to tell if Enter was pressed.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…