Explorar el Código

Allow playing/pausing with spacebar

master
Dylan Baker hace 4 años
padre
commit
05e950922f
Se han modificado 1 ficheros con 9 adiciones y 1 borrados
  1. 9
    1
      src/Controls.tsx

+ 9
- 1
src/Controls.tsx Ver fichero

@@ -1,4 +1,4 @@
1
-import React from 'react';
1
+import React, { useEffect } from 'react';
2 2
 
3 3
 interface Props {
4 4
   running: boolean;
@@ -33,6 +33,14 @@ const Controls = (props: Props) => {
33 33
     }
34 34
   };
35 35
 
36
+  useEffect(() => {
37
+    document.addEventListener('keyup', (e) => {
38
+      if (e.key === ' ') {
39
+        toggle();
40
+      }
41
+    });
42
+  }, [toggle]);
43
+
36 44
   return (
37 45
     <div className="controls">
38 46
       <div className="controls__section dimensions">

Loading…
Cancelar
Guardar