Javascript 获取预期赋值或函数调用的错误,并在react中看到一个表达式没有未使用的表达式
我在下面得到一个错误 第56:11行:应为赋值或函数调用,但看到的是表达式没有未使用的表达式Javascript 获取预期赋值或函数调用的错误,并在react中看到一个表达式没有未使用的表达式,javascript,reactjs,jsx,Javascript,Reactjs,Jsx,我在下面得到一个错误 第56:11行:应为赋值或函数调用,但看到的是表达式没有未使用的表达式 { (userPosts.length)? ( { userPosts.map((post,idx)=>{ }) } ) : ( 还没有帖子 ) } 请帮我解决这个问题。 提前感谢。传递给.map的函数没有返回任何内容 因此,要么添加返回: userPosts.map((post,idx) => { return ( <div className="smallPos
{
(userPosts.length)?
(
{
userPosts.map((post,idx)=>{
})
}
)
:
(
还没有帖子
)
}
请帮我解决这个问题。
提前感谢。传递给
.map
的函数没有返回任何内容
因此,要么添加返回:
userPosts.map((post,idx) => {
return (
<div className="smallPost">
<img className='smallPost_pic' alt='post_img' src={post.imageurl}/>
</div>
)
})
userPosts.map((post,idx)=>{
返回(
)
})
或者用括号替换大括号:
userPosts.map((post,idx) => (
<div className="smallPost">
<img className='smallPost_pic' alt='post_img' src={post.imageurl}/>
</div>
)
)
userPosts.map((post,idx)=>(
)
)
作为旁注,请记住将键添加到从.map
函数返回的div
。在React的文档中详细介绍:传递给.map
的函数没有返回任何内容
因此,要么添加返回:
userPosts.map((post,idx) => {
return (
<div className="smallPost">
<img className='smallPost_pic' alt='post_img' src={post.imageurl}/>
</div>
)
})
userPosts.map((post,idx)=>{
返回(
)
})
或者用括号替换大括号:
userPosts.map((post,idx) => (
<div className="smallPost">
<img className='smallPost_pic' alt='post_img' src={post.imageurl}/>
</div>
)
)
userPosts.map((post,idx)=>(
)
)
作为旁注,请记住将键添加到从.map
函数返回的div
。有关更多信息,请参见React的文档: