I want to run a function when detect key combination cmd+enter within a text-area.
And it need to be compatible with react hook.
I need some suggestion on how to do this.
useEffect(() => {
const listener = (event) => {
console.log('a', event.which)
if (event.which === 13 && event.which === 91) {
console.log('Enter key was pressed. Run your function.')
event.preventDefault()
// callMyFunction();
}
}
document.addEventListener('keydown', listener)
return () => {
document.removeEventListener('keydown', listener)
}
}, [])
This is my code, it doesn't regconize the combination.