homerboy homerboy - 3 months ago 24
CoffeeScript Question

If...then in JSX for Javascript

I've been writing Coffeescript/JSX and this is valid syntax:

<div>
<label>
<input type={if @state.name == "Test" then "checkbox"}/>
</label>
</div>


How do I do the same for plain Javascript? There is no
if...then
clause and I don't think I can do inline
if
checks like I can in Coffee?

Answer

Taking the answer from How to write an inline IF statement in JavaScript?

You can use the syntax 10 < 11 ? do this : do that where the ? is the then and the : is the else.