I'm trying to set up an onKeyPress event that will be triggered when a key is pressed while a 'Level' element is displayed. I know that the div needs to be focused for events to register, but I'm not sure how to do this with functional components.
const handleKeyPress = e => {
console.log(e);
}
export default () => {
const [currentLevel, setCurrentLevel] = useState(1);
return (
<Level onKeyPress={handleKeyPress} />
)
}