[英]How to fix “Expected an assignment or function call and instead saw an expression” in reactjs?
I am following Grinder tutorial on react.js with creating burgerapp. 我正在通过创建burgerapp来关注react.js上的Grinder教程。 I'm getting error:
我收到错误消息:
Line 6: Expected an assignment or function call and instead saw an expression no-unused-expressions
After trying by myself i copied his file from finished project and got exactly same error so now im confused if problem is somewhere else, i might be blind or something isn't up to date with his tutorial. 经过我自己的尝试,我从完成的项目中复制了他的文件,并得到了完全相同的错误,所以现在我很困惑,如果问题出在其他地方,我可能是盲目的或者他的教程不是最新的。 Already tried with adding return statements and changing to curly braces.
已经尝试添加return语句并更改为花括号。 Please keep in mind I saw this code in other stackoverflow but it looks exactly same.
请记住,我在其他stackoverflow中看到了此代码,但它看起来完全一样。
My code: 我的代码:
const controls = [
{ label: 'Salad', type: 'salad' }, //line 6 studio code says error is here
{ label: 'Bacon', type: 'bacon' },
{ label: 'Cheese', type: 'cheese' },
{ label: 'Meat', type: 'meat' },
];
const buildControls = (props) => (
<div className ={"BuildControls"}>
{controls.map(ctrl =>(
<BuildControl key={ctrl.label} label={ctrl.label}/>
))}
</div>
);
export default buildControls;
App should start showing build controls but right now it's not even compiling. 应用程序应该开始显示构建控件,但是现在它甚至还没有编译。 Please don't be harsh im beginner in this topic.
在这个主题上,请不要苛刻。
Try something like this: 尝试这样的事情:
const buildControls = (props) => {
const controlItems = controls.map(ctrl =>
<BuildControl key={ctrl.label} label={ctrl.label}/>
);
return(
<div className ={"BuildControls"}>
{controlItems}
</div>
);
};
Ok found solution it's me being blind, problem was in different file, curly braces without return statement, after adding return it's fixed. 确定找到解决方案是我失明,问题出在不同的文件中,没有return语句的花括号,添加return以后是固定的。 Error was shown in BuildControls but problem was in BuildControl.
在BuildControls中显示了错误,但是在BuildControl中出现了问题。
const BuildControl = (props) => {};
while it should be 虽然应该
const BuildControl = (props) => ();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.