react lifecycle to check conditional code example
Example 1: ternary operator 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>
);
}
Example 2: javascript in jsx
const name = 'Josh Perez';
const element = <h1>Hello, {name}</h1>;
//notice the use of {...} to jump from jsx to javascript.
ReactDOM.render(
element,
document.getElementById('root')
);