Skip to content

Instantly share code, notes, and snippets.

@Lego2012
Last active January 28, 2024 15:06
Show Gist options
  • Save Lego2012/50432e467076f1ae0344c59636b0614e to your computer and use it in GitHub Desktop.
Save Lego2012/50432e467076f1ae0344c59636b0614e to your computer and use it in GitHub Desktop.

If visible, show:

---
const isVisible = false;
---

{
    isVisible &&
    <h1>{obj.favorites[1].toUpperCase()}</h1>
}

If visible show first line, otherwise second line:

{
    isVisible &&
     ? <h1>{obj.favorites[1].toUpperCase()}</h1>
     : <h1>{obj.favorites[0].toUpperCase()}</h1>
}

Shorter version:

<h1>{obj.favorites[isVisible ? [1] : [0]].toUpperCase()}</h1>

Loop through data:

<ul>
    {
        obj.favorites.map(item => (
            <li>{item}</li>
        ))
    }
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment