MCPcopy
hub / github.com/joshwcomeau/use-sound / useKeyboardBindings

Function useKeyboardBindings

stories/demos/DrumMachine.js:9–25  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7import drumSfx from '../sounds/909-drums.mp3';
8
9const useKeyboardBindings = map => {
10 React.useEffect(() => {
11 const handlePress = ev => {
12 const handler = map[ev.key];
13
14 if (typeof handler === 'function') {
15 handler();
16 }
17 };
18
19 window.addEventListener('keydown', handlePress);
20
21 return () => {
22 window.removeEventListener('keydown', handlePress);
23 };
24 }, [map]);
25};
26
27function DrumMachine() {
28 const [play] = useSound(drumSfx, {

Callers 1

DrumMachineFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…