reactjs - reactjs中没有评论时如何显示消息?
问题描述
当帖子没有任何评论时,我想向用户显示一条消息...
所以我有一张这样的地图
{comments.length === 0 ? (
comments.map((comment, key) => {
// codes here......
);
})
) : (
<>
<h2>There is no comment yet...</h2>
</>
)}
在这里,我正在检查comments.length是否没有评论,但是当有评论时它会显示消息并隐藏评论状态,但是当没有评论时,它不会显示消息。
有什么建议么?
解决方案
{comments.length > 0 ? () : () }
或者
{comments.length !== 0 ? () : () }
推荐阅读
- php - 从 HTML 到 PHP 的数据始终为空
- java - JAXB 编组和解组
- html - html .loads 有很大的余量
- wordpress - 自定义 WooCommerce 重写 URL
- r - rnorm 函数,但用于二项分布
- firebase - 将 firebase-admin 与 Deno 一起使用的可能方法
- scala - 无法在 HDP 3.0 中将 Spark Dataframe 保存为表
- python - _int_() 缺少 1 个必需的位置参数:on_delete
- email - 错误:在对象 DriveApp 上获取方法或属性 > getFileById 时出现意外错误
- android - android studio 上的 SQLite 将随机数分配给 ID 并且不会更新