[英]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.