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