我是一个全新的反应者,正在尝试遵循本教程。不幸的是,其中有一个错误。因为我不知道如何使用反应,所以我不知道如何解决它。

我正在尝试按照本教程-> https://medium.com/@williamyang93/my-journey-with-react-native-game-engine-part-i-starting-the-project-bbebcd2ccf6

我认为这部分代码有误:

export default class App extends React.Component {
render() {
   return (
    <GameEngine
    style={styles.container}
    entities={{ initialBox: {
               body: initialBox,
               size: [boxSize, boxSize],
               color: 'red',
               renderer: Box
         }}>
    <StatusBar hidden={true} />
    </GameEngine>
        );
  }


}

当我尝试运行app.js时,出现以下错误:Adjacent JSX elements must be wrapped in an enclosing tag.

我的第一个想法是删除第六行上多余的{,因此:

export default class App extends React.Component {
    render() {
       return (
        <GameEngine
        style={styles.container}
        entities={ initialBox: {
                   body: initialBox,
                   size: [boxSize, boxSize],
                   color: 'red',
                   renderer: Box
             }}>
        <StatusBar hidden={true} />
        </GameEngine>
            );
      }
}


但随后我得到:Expected "}"

有人可以帮我解决此错误,以便我继续本教程吗?

最佳答案

您缺少内部对象的右花括号:

<GameEngine
    style={styles.container}
    entities={{
        initialBox: {
            body: initialBox,
            size: [boxSize, boxSize],
            color: 'red',
            renderer: Box,
        } // this is missing
    }}
>
    <StatusBar hidden={true} />
</GameEngine>

09-09 19:57
查看更多