Skip to content

Commit 3dddb5b

Browse files
Anna LindgrenAnna Lindgren
Anna Lindgren
authored and
Anna Lindgren
committed
added map method to render game action
1 parent 1547f2a commit 3dddb5b

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

code/src/components/GameScreen.js

+14-10
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,26 @@ import { useSelector } from 'react-redux'
44
const GameScreen = () => {
55
const userActions = useSelector(store => store.games.username)
66
// console.log(userActions)
7-
7+
88
const games = useSelector(store => store.games.username.actions)
9+
// const games = useSelector(store => store.games)
910
console.log(games)
1011

12+
13+
//The optional chaining operator (?.)
14+
//enables you to read the value of a property located deep within
15+
//a chain of connected objects without having to check that each reference
16+
//in the chain is valid.
1117
return (
1218
<div>
1319
<h3>{userActions.description}</h3>
14-
{/* <p>{games.description}</p> */}
15-
{/* {userActions.map(action => (
16-
<button
17-
key={action}
18-
onClick=""
19-
>
20-
{action}
21-
</button>
22-
))} */}
20+
{games?.map( (game, index) => (
21+
<div key={index}>
22+
<p>{game.description}</p>
23+
<button>{game.direction}</button>
24+
</div>
25+
)
26+
)}
2327
</div>
2428
)
2529
}

code/src/reducers/games.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export const games = createSlice({
55
initialState: {
66
coordinates: null,
77
description: null,
8-
actions:[],
8+
// actions:[],
99
username: ''
1010
},
1111
reducers: {

0 commit comments

Comments
 (0)