Trying to call one of my functions inside this window.onkeydown function but I am out of scope. Any ideas what I can do?
componentDidMount() {
setTimeout(() => {
window.onkeydown = function(e) {
if (e.keyCode === 13) {
console.log("Enter detected");
// this.handleNextCard(); // this function will throw an error: undefined
}
};
}, 250);
}
componentWillUnmount() {
window.onkeydown = null;
}
handleFlipCard() {
this.props.toggleViewAnswer();
}
handleNextCard() {
this.props.selectNextCard();
}
render(){}