Created
November 1, 2021 11:28
-
-
Save mjanssen/ae839866ef13c0191c7dae5a71d82fd0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useEffect, useState } from "react"; | |
export default function Piano() { | |
const [key, setKey] = useState(null); | |
useEffect(() => { | |
function onKeyPress(e) { | |
e.preventDefault(); | |
const key = e.key.toLowerCase(); | |
setKey(key); | |
} | |
window.addEventListener('keyDown', onKeyPress); | |
return () => { | |
window.removeEventListener('keyDown', onKeyPress); | |
} | |
}, []) | |
return <Component keys={key} /> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment