if react statement code example

Example 1: if else render react

render() {
  const isLoggedIn = this.state.isLoggedIn;
  return (
    
{isLoggedIn ? ( ) : ( )}
); }

Example 2: make a if in jsx

var loginButton;
if (loggedIn) {
  loginButton = ;
} else {
  loginButton = ;
}

return (
  
);

Example 3: adding a if stement in jsx

render() {
    return (   
        
            {this.state.value == 'news'? data: null }
        
    )
}

Example 4: react if statement

render() {
  const isLoggedIn = this.state.isLoggedIn;
  return (
    
The user is {isLoggedIn ? 'currently' : 'not'} logged in.
); }

Tags:

Misc Example