mardi 21 novembre 2017

What is the best way to write a simple condition in JSX?

in my jsx

       <div>{person.age}</div>

I want to display below only if the person is age 50 or above

<div className="red-text">{person.age}</div>

to do this I put a var let olderPerson = person.age > 50; and then did this

    {olderPerson ? (
        <div className="red-text">{person.age }</div>
        ): (<div >{person.age }</div>)
        }

LMK if this correct way to do this

Aucun commentaire:

Enregistrer un commentaire