react if statement in return function code example
Example 1: react if statement
render() {
const isLoggedIn = this.state.isLoggedIn;
return (
The user is {isLoggedIn ? 'currently' : 'not'} logged in.
);
}
Example 2: javascript in jsx
const name = 'Josh Perez';
const element = Hello, {name}
;
//notice the use of {...} to jump from jsx to javascript.
ReactDOM.render(
element,
document.getElementById('root')
);