简体   繁体   English

如何在reactjs中修复“预期的分配或函数调用,而看到一个表达式”?

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

相关问题 ReactJS错误:“预期分配或函数调用,而是看到了一个表达式” - ReactJS error: “Expected an assignment or function call and instead saw an expression” ReactJS 错误:“__”未定义 &amp; 预期分配或 function 调用,而是看到一个表达式? - ReactJS errors: “__” is not defined & Expected an assignment or function call and instead saw an expression? 修复 - 预期分配或 function 调用,而是看到一个表达式 - Fix - expected an assignment or function call and instead saw an expression 期望赋值或函数调用,而是看到了一个表达式 - Expected an assignment or function call and instead saw an expression 期望一个赋值或函数调用,而是看到一个表达式? - Expected an assignment or function call and instead saw an expression? 期望一个赋值或函数调用,而是看到一个表达式 - Expected an assignment or function call and instead saw an expression 预期分配或 function 调用,而是看到一个表达式 no-unused-expressions - 如何修复此 CI 错误? - Expected an assignment or function call and instead saw an expression no-unused-expressions - how to fix this CI error? 期望赋值或函数调用,而在使用graphcms时在reactjs中看到一个表达式 - Expected an assignment or function call and instead saw an expression in reactjs while using graphcms return function returning预期的赋值或函数调用,而是看到一个表达式 - return function returning Expected an assignment or function call and instead saw an expression 试图修复我的反应类组件。 收到错误“期望赋值或函数调用,但看到了一个表达式” - Trying to fix my react class component. Getting the error "Expected an assignment or function call and instead saw an expression"
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM