Gustavo
Gustavo

Reputation: 39

React & HTML: Highlight a table cell with booleans

I'm using React, and was wondering wether it is possible to highlight a table cell with a boolean, kind of this here:

 <table>
  <tr>
    <td {if (highlight)  bgColor = 'red'} >Emil</td>
    <td>Tobias</td>
    <td>Linus</td>
  </tr>
</table> 

(Where highlight is a boolean state variable).

Upvotes: 0

Views: 105

Answers (1)

Ryan Le
Ryan Le

Reputation: 8412

Yes, you can. Simply use a ternary operator for that:

<td style={{backgroundColor: highlight ? 'red' : ''}} >Emil</td>

Upvotes: 1

Related Questions