Currently, in my React app I have this,
<input style={{ borderColor: valid ? null : "red", boxShadow: valid ? null : "rgb(2, 0, 0)"}} />
If I have more styling to do, it doesn't make sense checking the same condition again and again right? I wish to make the entire style attribute optional; something like this,
<input valid ? null : style={{ borderColor: "red", boxShadow: "rgb(2, 0, 0)"}} />
But I know that's not the right syntax. Isn't there a better way to do this?
You should use className to add style classes conditionally.You can use the classnames package as answered to the question
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With