File tree Expand file tree Collapse file tree 1 file changed +17
-6
lines changed
workspaces/simon-game/src/app/components Expand file tree Collapse file tree 1 file changed +17
-6
lines changed Original file line number Diff line number Diff line change 1
- import React from "react" ;
1
+ import React , { useState } from "react" ;
2
2
3
3
import { Box } from "./Box.tsx" ;
4
4
import { playNote } from "../util/playNote.ts" ;
5
5
import { config } from "../constants.ts" ;
6
6
7
7
export function App ( ) {
8
+ const [ playerMoves , setPlayerMoves ] = useState < readonly number [ ] > ( [ ] ) ;
8
9
return (
9
- < div style = { { display : "flex" , gap : 10 } } >
10
- { config . boxes . map ( ( box ) => (
11
- < Box color = { box . color } onClick = { ( ) => playNote ( box . frequency ) } />
12
- ) ) }
13
- </ div >
10
+ < >
11
+ < div style = { { display : "flex" , gap : 10 } } >
12
+ { config . boxes . map ( ( box , index ) => (
13
+ < Box
14
+ key = { index }
15
+ color = { box . color }
16
+ onClick = { ( ) => {
17
+ playNote ( box . frequency ) ;
18
+ setPlayerMoves ( ( prev ) => [ ...prev , index ] ) ;
19
+ } }
20
+ />
21
+ ) ) }
22
+ </ div >
23
+ < pre > { JSON . stringify ( playerMoves , null , 2 ) } </ pre >
24
+ </ >
14
25
) ;
15
26
}
You can’t perform that action at this time.
0 commit comments