I currently like to format my ternaries like this in react:
render () {
return (
<div className="row">
{ //Check if message failed
(this.state.message === 'failed')
? <div> Something went wrong </div>
: <div> Everything in the world is fine </div>
}
</div>
);
}
You are correct that IIFEs can be used within a render statement as well as ternary expressions. Using a normal if .. else
statement is valid, but the render
function’s return statement can only contain expressions so you would have to do those elsewhere..