简体   繁体   English

预期的“}”或相邻的 JSX 元素必须包含在封闭标记中

[英]Expected "}" OR Adjacent JSX elements must be wrapped in an enclosing tag

I'm totally new to react and am trying to follow this tutorial.我对反应完全陌生,正在尝试按照本教程进行操作。 Unfortunately, there is an error in it.不幸的是,其中有一个错误。 Because I have no idea how to use react, I don't know how to fix it.因为我不知道如何使用反应,所以我不知道如何修复它。

I'm trying to follow this tutorial --> https://medium.com/@williamyang93/my-journey-with-react-native-game-engine-part-i-starting-the-project-bbebcd2ccf6我正在尝试按照本教程进行操作 --> https://medium.com/@williamyang93/my-journey-with-react-native-game-engine-part-i-starting-the-project-bbebcd2ccf6

I think there is a mistake with this part of the code:我认为这部分代码有错误:

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>
        );
  }

} }

When I try and run my app.js with that I get this error: Adjacent JSX elements must be wrapped in an enclosing tag.当我尝试运行我的 app.js 时,我得到了这个错误: Adjacent JSX elements must be wrapped in an enclosing tag.

My first thought was to remove the extra { on the 6th line, so this:我的第一个想法是删除第 6 行多余的{ ,这样:

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>
            );
      }
}

But then I get: Expected "}"但后来我得到: Expected "}"

Can someone help me fix this error is so I can continue with the tutorial?有人可以帮我解决这个错误,这样我就可以继续学习教程了吗?

You are missing the closing curly brace of your inner object:您缺少内部 object 的右花括号:

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

Its a good idea to keep your render function return as simple as possible like:使您的渲染 function 返回尽可能简单是个好主意,例如:

export default class App extends React.Component {
render() {

   let box = {
      initialBox: {
          body: initialBox, 
          size: [boxSize, boxSize], 
          color: 'red', 
          renderer: Box
      }  // <-- this was missing in your code
   }

   return (
      <GameEngine style={styles.container} entities={box}>
         <StatusBar hidden={true} />
      </GameEngine>
   );
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 必须将相邻的JSX元素包装在带有换行符标记的封闭标记中 - Adjacent JSX elements must be wrapped in an enclosing tag with line break tag 相邻的 JSX 元素必须包含在图像的封闭标签中吗? - Adjacent JSX elements must be wrapped in an enclosing tag for Images? 错误:相邻的JSX元素必须包装在封闭标记中 - Error: Adjacent JSX elements must be wrapped in an enclosing tag 解析错误:必须将相邻的 JSX 元素包装在封闭标记中 - Parsing error: Adjacent JSX elements must be wrapped in an enclosing tag 相邻的JSX元素必须包装在一个封闭标签中-gatsby.js - Adjacent JSX elements must be wrapped in an enclosing tag - gatsby.js 解析错误:相邻的 JSX 元素必须包含在封闭标记中 - Parse Error: Adjacent JSX elements must be wrapped in an enclosing tag Reactstrap:“相邻的 JSX 元素必须包裹在封闭标签中”? - Reactstrap: "Adjacent JSX elements must be wrapped in an enclosing tag"? SyntaxError:相邻的 JSX 元素必须包含在封闭标记中 - SyntaxError: Adjacent JSX elements must be wrapped in an enclosing tag 相邻的JSX元素必须包装在一个封闭的标记React Native中 - Adjacent JSX elements must be wrapped in an enclosing tag React Native 相邻的 JSX 元素必须包含在封闭标记中 (34:0) - Adjacent JSX elements must be wrapped in an enclosing tag (34:0)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM