1
- import React from 'react'
2
- import { useSelector } from 'react-redux'
1
+ import React , { useState } from 'react'
2
+ import { useSelector , useDispatch } from 'react-redux'
3
+
4
+ import { games , CarryOnGame } from '../reducers/games'
5
+
6
+ const GameScreen = ( { inputValue } ) => {
7
+ const [ inputDirection , setInputDirection ] = useState ( [ ] )
3
8
4
- const GameScreen = ( ) => {
5
9
const userActions = useSelector ( store => store . games . username )
6
10
// console.log(userActions)
7
11
8
12
const games = useSelector ( store => store . games . username . actions )
9
13
// const games = useSelector(store => store.games)
10
14
console . log ( games )
11
15
16
+ const dispatch = useDispatch ( )
17
+
18
+ /* const onNextDirection = () => {
19
+ dispatch(games.actions.setInputDirection(inputDirection))
20
+ dispatch(CarryOnGame(inputValue)) // ?
21
+ } */
12
22
13
23
//The optional chaining operator (?.)
14
24
//enables you to read the value of a property located deep within
@@ -20,7 +30,10 @@ const GameScreen = () => {
20
30
{ games ?. map ( ( game , index ) => (
21
31
< div key = { index } >
22
32
< p > { game . description } </ p >
23
- < button > { game . direction } </ button >
33
+ < button
34
+ onClick = { ( ) => dispatch ( ) } >
35
+ { game . direction }
36
+ </ button >
24
37
</ div >
25
38
)
26
39
) }
0 commit comments