简体   繁体   中英

./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 (
  <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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM