Template variables

const showComments = true;
const commentBlock = (
<div className='comments'>
  <h3>Comments {comments.length}</h3>
  <ul>
    {comments.map((comment, index) => (
      <li key={index}>{comment.text}</li>
    ))}
  </ul>
</div>
);

If showComments is true, display commentBlock

{showComments && commentBlock}
Was this page helpful?