首页 > 解决方案 > reactjs中没有评论时如何显示消息?

问题描述

当帖子没有任何评论时,我想向用户显示一条消息...

所以我有一张这样的地图

  {comments.length === 0 ? (
          comments.map((comment, key) => {
          // codes here......
      );
          })
        ) : (
          <>
            <h2>There is no comment yet...</h2>
          </>
        )}

在这里,我正在检查comments.length是否没有评论,但是当有评论时它会显示消息并隐藏评论状态,但是当没有评论时,它不会显示消息。

有什么建议么?

标签: reactjs

解决方案


{comments.length > 0 ? () : () }

或者

{comments.length !== 0 ? () : () }

推荐阅读