Created
February 2, 2022 01:59
-
-
Save jx13xx/e29103b6ae2cb7db278f6dbc68b27d67 to your computer and use it in GitHub Desktop.
Conditionals in JSX
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const showComments = true; | |
function App() { | |
return ( | |
<div className='container'> | |
<h1>Blog Post</h1> | |
{showComments ? (<div className='comments'> | |
<h3>Comments ({comments.length})</h3> | |
<ul> | |
{comments.map((comment, index) => ( | |
<li key={index}>{comment.text}</li> | |
))} | |
</ul> | |
</div>) : 'no'} | |
// OR | |
{showComments && (<div className='comments'> | |
<h3>Comments ({comments.length})</h3> | |
<ul> | |
{comments.map((comment, index) => ( | |
<li key={index}>{comment.text}</li> | |
))} | |
</ul> | |
</div>)} | |
</div> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment