I'm having trouble getting event.key from input onKeyPress event, getting this error when i type in the input field - TypeError: Cannot read property 'key' of undefined
The plan is to update parent state when enter is pressed in child input component.
class ToDoList extends Component {
constructor(props) {
super(props);
this.handleKeyPress = this.handleKeyPress.bind(this);
this.state = {
todoArr: [],
};
}
handleKeyPress(e){
console.log(e.key);
}
render(){
return(
<div className="wrapper">
<p className = "title">todos</p>
<InputField testProp={this.handleKeyPress}></InputField>
<div className = "filter-wrap">
<ItemsLeft></ItemsLeft>
<Filter></Filter>
<ClearCompleted></ClearCompleted>
</div>
</div>
)
}
}
class InputField extends Component {
render(){
return(
<input type="text" className="input-field" onKeyPress = {()=> this.props.testProp()}/>
)
}
}
