I’m trying to build a Tic Tac Toe app that will let me choose 3×3, 4×4 and 5×5 grid and currently i’m stuck on 3×3 grid and I’m getting ‘JSX expressions must have one parent element.ts(2657)’
JavaScript
x
49
49
1
const newGameState = {
2
squares: Array(9).fill(null),
3
xIsNext: true,
4
}
5
6
class Game3x3 extends React.Component {
7
constructor(props) {
8
super(props)
9
this.state = newGameState
10
}
11
12
whoseTurn() {
13
return this.state.xIsNext ? 'X' : 'O'
14
}
15
16
onNewGame() {
17
this.setState(newGameState)
18
}
19
20
onMove(i) {
21
let newSquares = this.state.squares.slice()
22
const turn = this.whoseTurn()
23
if (this.state.squares[i] || winner(this.state.squares)) return null
24
newSquares[i] = turn
25
this.setState({
26
squares: newSquares,
27
xIsNext: !this.state.xIsNext,
28
})
29
}
30
31
32
render() {
33
const style = {
34
backgroundColor: 'beige',
35
flex: 1,
36
alignItems: 'center',
37
}
38
// this is the return statement that give me an error v
39
return (
40
<SafeAreaView style={style}>
41
<Board squares={this.state.squares} onMove={(i) => this.onMove(i)} />
42
<Status turn={this.whoseTurn()} winner={winner(this.state.squares)} onNewGame={() => this.onNewGame()} />
43
</SafeAreaView>
44
)
45
46
47
48
}
49
I tried adding another view element but it didn’t work. I will be gratefull to hear your suggestions.
Advertisement
Answer
It’s a appears that I didn’t have to use that return statement.