DaveDavidson DaveDavidson - 10 months ago 50
React JSX Question

Change text colour depending on if condition react

I want to use something similar to

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 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 style={styles.listThree}>
<li style={styles.li}><span style={styles.fontLink}>Nessuna informazione personale</span></li>

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

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

Please note, I cannot use

Answer Source

Why not doing something like this:

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