DaveDavidson DaveDavidson - 9 days ago 6
React JSX Question

Change text colour depending on if condition react

I want to use something similar to

getElementById
in order to select my element and change the text colour. I currently have a unordered list, and wish to change the colour of each individual depending on an if condition.

<div style={styles.passwordRules}>
<ul style={styles.listOne}>
<li style={styles.li}><span style={styles.error} id="test">8 a 16 caratteri</span></li>
<li style={styles.li}><span style={styles.fontNormal}>Carattere maiuscolo</span></li>
</ul>
<ul style={styles.listTwo}>
<li style={styles.li}><span style={styles.fontNormal}>Un numero</span></li>
<li style={styles.li}><span style={styles.fontNormal}>Carattere minuscolo</span></li>
</ul>
<ul style={styles.listThree}>
<li style={styles.li}><span style={styles.fontLink}>Nessuna informazione personale</span></li>
</ul>
</div>


Meaning that for instance, I would like something similar to this:

if(text === 'foo') {
//change colour to grey
}


Please note, I cannot use
getElementById

Answer

Why not doing something like this:

<li className={text === 'foo' ? styles.class1 : styles.class2 } .../>