I have a utility function, but this
is undefined even I bind it in my react component:
/util/index:
export const handleKeyPress = e =>{
console.log(this)
}
/component/input/:
import {handleKeyPress} from "../util/index"
class Input extends Component {
constructor(props) {
super(props)
this.state = {
isOpen: false
}
}
this.handleKeyPress = handleKeyPress.bind(this)
render(){
return <input onKeyPress = {this.handleKeyPress} />
}
}
So on my input keypress, this
is undefined in the function even I bind it inside my constructor. What can I do?