Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 获取预期赋值或函数调用的错误,并在react中看到一个表达式没有未使用的表达式_Javascript_Reactjs_Jsx - Fatal编程技术网

Javascript 获取预期赋值或函数调用的错误,并在react中看到一个表达式没有未使用的表达式

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

我在下面得到一个错误

第56:11行:应为赋值或函数调用,但看到的是表达式没有未使用的表达式


{
(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的文档: