Answer the question
In order to leave comments, you need to log in
How to change the text in react depending on the value?
Hello, I want to make it so that if the value is 0, then the color becomes red.. Here's how I did it, but it doesn't work)
<p style={{color: "{ (this.state.petrol > 0) ? '#ffffff' : '#D12828'}" }}>{this.state.petrol}l</p>
Answer the question
In order to leave comments, you need to log in
const color = this.state.petrol > 0 ? "#FFF" : "#D12828";
return (
<p style={{ color }}>{this.state.petrol}</p>
);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question