I would like to dispatch onKeyDown events from a body element too a div inside of the body.
I am using React and have tried adding an onKeyDown event listener to my body tag in the componentDidMount function of my React component.
componentDidMount() {
document.getElementById("main-content").onkeydown = event => {
document.getElementById("Keyboard").dispatchEvent(event);
}
}
I expected the keydown event to be dispatched to the Keyboard component, but instead I receive the error listed below.
InvalidStateError: An attempt was made to use an object that is not, or is no longer, usable.
Any help would be appreciated!