简体   繁体   English

得到预期的赋值或函数调用的错误,而是在反应中看到了一个表达式 no-unused-expressions

[英]getting an error of Expected an assignment or function call and instead saw an expression no-unused-expressions in react

I am getting an error of in the below我在下面收到错误

Line 56:11: Expected an assignment or function call and instead saw an expression no-unused-expressions第 56:11 行:期望赋值或函数调用,但看到的是表达式 no-unused-expressions

<div className="posts_container">
{
    (userPosts.length) ?
        (
            <div>
            {
                userPosts.map((post,idx)=>{
                    <div className="smallPost">
                        <img className='smallPost_pic' alt='post_img' src={post.imageurl}/>
                    </div>
                })
            }
            </div>
        )
        :
        (
            <h1> No posts Yet </h1>
        )
}
</div>

please help me to solve this.请帮我解决这个问题。 Thanks in advance.提前致谢。

The function that's passed to .map isn't returning anything.传递给.map的函数没有返回任何内容。

So either add return :所以要么添加return

userPosts.map((post,idx) => {
  return (
    <div className="smallPost">
      <img className='smallPost_pic' alt='post_img' src={post.imageurl}/>
    </div>
  )
})

or replace the curly braces with parentheses:或用括号替换花括号:

userPosts.map((post,idx) => (
    <div className="smallPost">
      <img className='smallPost_pic' alt='post_img' src={post.imageurl}/>
    </div>
  )
)

As a sidenote, remember to add a key to the div that is returned from the .map function.作为旁注,请记住向从.map函数返回的div添加一个key More about that in React's docs: Lists and Keys更多关于 React 的文档: Lists and Keys

暂无
暂无

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

相关问题 在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? - Getting the error that Expected an assignment or function call and instead saw an expression no-unused-expressions? 期望一个赋值或函数调用,而是在React中看到一个表达式no-unused-expressions错误 - Expected an assignment or function call and instead saw an expression no-unused-expressions error in React 获得预期的赋值或函数调用,而是在尝试在 React 中呈现组件时看到表达式 no-unused-expressions 错误 - Getting Expected an assignment or function call and instead saw an expression no-unused-expressions error when trying to render a component in React 重定向(反应路由器dom),给出了期望的赋值或函数调用,而是看到了一个表达式no-unused-expressions - Redirect (react router dom) giving Expected an assignment or function call and instead saw an expression no-unused-expressions 反应:期望一个赋值或函数调用,而是看到一个表达式 no-unused-expressions - React: expected an assignment or function call and instead saw an expression no-unused-expressions 期望一个赋值或 function 调用,而是在尝试使用 react 制作组件时看到一个表达式 no-unused-expressions - Expected an assignment or function call and instead saw an expression no-unused-expressions when trying to make a component using react 预期分配或 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? 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
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM