i have a table i wanna attach arrow keys to each cell wanna implement something like https://jsfiddle.net/rh5aoxsL/ in react but then not able to do so as some where m going wrong can anyone lemme know what has to be done
import React, { Component } from 'react';
import './App.css';
class App extends Component {
constructor(props){
super(props);
this.escFunction = this.escFunction.bind(this);
}
escFunction(event){
if(event.keyCode === 37) {
console.log("----------37---------------");
}
if(event.keyCode === 38) {
console.log("----------38---------------");
}
if(event.keyCode === 39) {
console.log("----------39---------------");
}
if(event.keyCode === 40) {
console.log("----------40---------------");
}
}
componentDidMount(){
document.addEventListener("keydown", this.escFunction, false);
}
componentWillUnmount(){
document.removeEventListener("keydown", this.escFunction, false);
}
render() {
return (
<div className="App">
<table >
<tbody>
<tr>
<td id="start" onKeyDown={this.escFunction}>1</td>
<td onKeyDown={this.escFunction}>2</td>
</tr>
<tr>
<td onKeyDown={this.escFunction}>3</td>
<td onKeyDown={this.escFunction}>4</td>
</tr>
</tbody>
</table>
</div>
);
}
}
export default App;
any help is appreciated
handleKeyPressbut you are using in the callback. So shouldn't it beescFunction?