I\'m trying to implement some very basic key press detection and I can\'t get it to work at all. I have a bare component that should be picking up on the onKeyDown
You'll need to assign a tabIndex-attribute for your element (the wrapping element for example) for it to receive keypresses. Then pass the keyDown handler to it with the props:
import React from 'react';
import { render } from 'react-dom';
class ChildComponent extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
Fooo
);
}
}
class App extends React.Component {
constructor(props) {
super(props);
}
handleKeyDown(event) {
console.log('handling a key press');
}
render() {
return (
this.handleKeyDown()} />
);
}
}
render( , document.getElementById('app'));