Answer the question
In order to leave comments, you need to log in
How to assign style depending on value?
I have the following code:
renderCrypto(obj,index){
return(
<div key={index} className='col-md-3'>
<button type="button" className="btn btn-light">
<a style={{ color: "rgb(2, 214, 19)" }}>({obj.percent_change_24h})%</a>
</button>
</div>
)}
Answer the question
In order to leave comments, you need to log in
renderCrypto(obj,index){
const percentColor = obj.percent_change_24h === -2' ? 'red' : 'rgb(2, 214, 19);
return(
<div key={index} className='col-md-3'>
<button type="button" className="btn btn-light">
<a style={{ color: percentColor }}>({obj.percent_change_24h})%</a>
</button>
</div>
)}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question