У меня есть служебная функция, но this
не определено, даже если я связываю ее в своем реактивном компоненте:
/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} />
}
}
Таким образом, при моем нажатии клавиши this
не определено в функции, даже если я связываю ее внутри своего конструктора. Что я могу сделать?