Javascript JSX表达式在返回语句中必须有一个父元素.ts(2657)
我正在尝试构建一个Tic-Tac-Toe应用程序,它可以让我选择3x3、4x4和5x5网格,目前我被困在3x3网格上,我得到了“JSX表达式必须有一个父元素。ts(2657)”Javascript JSX表达式在返回语句中必须有一个父元素.ts(2657),javascript,react-native,Javascript,React Native,我正在尝试构建一个Tic-Tac-Toe应用程序,它可以让我选择3x3、4x4和5x5网格,目前我被困在3x3网格上,我得到了“JSX表达式必须有一个父元素。ts(2657)” const newGameState={ 正方形:数组(9)。填充(空), 下一个:是的, } 类Game3x3扩展了React.Component{ 建造师(道具){ 超级(道具) this.state=newGameState } whoseTurn(){ 返回this.state.xIsNext?'X':'O' }
const newGameState={
正方形:数组(9)。填充(空),
下一个:是的,
}
类Game3x3扩展了React.Component{
建造师(道具){
超级(道具)
this.state=newGameState
}
whoseTurn(){
返回this.state.xIsNext?'X':'O'
}
onNewGame(){
this.setState(新游戏状态)
}
onMove(一){
让newSquares=this.state.squares.slice()
const turn=this.whoseTurn()
if(this.state.squares[i]| | winner(this.state.squares))返回null
新闻广场
这是我的国家({
广场:新闻广场,
xIsNext:!this.state.xIsNext,
})
}
render(){
常量样式={
背景颜色:“米色”,
弹性:1,
对齐项目:“居中”,
}
//这是返回语句,它给了我一个错误v
返回(
这个.onMove(i)}/>
this.onNewGame()}/>
)
}
我尝试添加另一个视图元素,但没有成功。如果能听到你的建议,我将不胜感激。看来我不必使用那个返回声明
const newGameState = {
squares: Array(9).fill(null),
xIsNext: true,
}
class Game3x3 extends React.Component {
constructor(props) {
super(props)
this.state = newGameState
}
whoseTurn() {
return this.state.xIsNext ? 'X' : 'O'
}
onNewGame() {
this.setState(newGameState)
}
onMove(i) {
let newSquares = this.state.squares.slice()
const turn = this.whoseTurn()
if (this.state.squares[i] || winner(this.state.squares)) return null
newSquares[i] = turn
this.setState({
squares: newSquares,
xIsNext: !this.state.xIsNext,
})
}
render() {
const style = {
backgroundColor: 'beige',
flex: 1,
alignItems: 'center',
}
// this is the return statement that give me an error v
return (
<SafeAreaView style={style}>
<Board squares={this.state.squares} onMove={(i) => this.onMove(i)} />
<Status turn={this.whoseTurn()} winner={winner(this.state.squares)} onNewGame={() => this.onNewGame()} />
</SafeAreaView>
)
}