F
F
frolldoll2018-03-22 13:26:10
React
frolldoll, 2018-03-22 13:26:10

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>
            )}

In obj.percent_change_24h a value is stored - for example (2%) or (-2%)
How to check for example if there is -2% then color will be red?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
TheLostRoot, 2018-03-22
@frolldoll

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 question

Ask a Question

731 491 924 answers to any question