简体   繁体   English

./src/index.js第36行:预期执行赋值或函数调用,而是看到一个表达式no-unused-expressions

[英]./src/index.js Line 36: Expected an assignment or function call and instead saw an expression no-unused-expressions

i am running map function but not getting result due to this 我正在运行地图功能,但由于此而没有得到结果

    return (
        <div>
         <ul>
         {items.map((item)=>{
             return
             <li key={item.id}>{item.name}</li>
         })}
         </ul>
        </div>
    )

Make sure to keep your return statement and the code it returns on the same line: 确保将return语句和返回的代码放在同一行:

return (
  <div>
    <ul>
      {items.map(item => {
        return <li key={item.id}>{item.name}</li>; // this should be one line
      })}
    </ul>
  </div>
);

Otherwise automatic semicolon insertion will put a semicolon after your return and as a result the map will return an array of undefined values. 否则, 自动分号插入将在您return后加上分号,结果map将返回undefined值的数组。

Change your code like this, see if it works 像这样更改您的代码,看看是否可行

return ( < div> < ul> {items.map
(item=>  < li key={item.id}>{item.name}
 < /li> )} </ ul> </ div> )

And be sure you have an array in your items Hope it works for you 并且确保您的商品中有一个数组希望它对您有用

Update : it was buggy and editor hidden my < li > tag, so I put space before li 更新:这是越野车,编辑器隐藏了我的<li>标记,因此我在li之前放置了空格

暂无
暂无

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

相关问题 得到预期赋值或函数调用的错误,而是看到一个表达式 no-unused-expressions? - Getting the error that Expected an assignment or function call and instead saw an expression no-unused-expressions? 得到预期的赋值或函数调用的错误,而是在反应中看到了一个表达式 no-unused-expressions - getting an error of Expected an assignment or function call and instead saw an expression no-unused-expressions in react 期望一个赋值或函数调用,而是在React中看到一个表达式no-unused-expressions错误 - Expected an assignment or function call and instead saw an expression no-unused-expressions error in React Object.keys-需要一个赋值或函数调用,而是看到一个表达式no-unused-expressions - Object.keys - Expected an assignment or function call and instead saw an expression no-unused-expressions 如何解决这个 期望赋值或函数调用,而是看到一个表达式 no-unused-expressions - how to solve this Expected an assignment or function call and instead saw an expression no-unused-expressions 重定向(反应路由器dom),给出了期望的赋值或函数调用,而是看到了一个表达式no-unused-expressions - Redirect (react router dom) giving Expected an assignment or function call and instead saw an expression no-unused-expressions “预期分配或 function 调用,而是在我的聊天应用程序中看到一个表达式 no-unused-expressions” - “Expected an assignment or function call and instead saw an expression no-unused-expressions” in my chat app 在React中导入文件时,获得期望的赋值或函数调用,而是看到一个表达式no-unused-expressions - Getting Expected an assignment or function call and instead saw an expression no-unused-expressions, when import a file in React 反应:期望一个赋值或函数调用,而是看到一个表达式 no-unused-expressions - React: expected an assignment or function call and instead saw an expression no-unused-expressions 期望一个赋值或函数调用,而是看到一个表达式no-unused-expressions(第14/15行) - Expected an assignment or function call and instead saw an expression no-unused-expressions (lines 14/15)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM