if else statement in return react code example

Example 1: if else react render in jsc

const functionalComponent=()=> {

  return (
    <div>{
  			  props.isFeatured ? (
                        <div className="featured_ovelay_icon">lol</div>

                    ) : ("")
 			}
    </div>
  );
}

Example 2: if else render react

render() {
  const isLoggedIn = this.state.isLoggedIn;
  return (
    <div>
      {isLoggedIn ? (
        <LogoutButton onClick={this.handleLogoutClick} />
      ) : (
        <LoginButton onClick={this.handleLoginClick} />
      )}
    </div>
  );
}

Example 3: how to use if else inside jsx in react

renderElement(){
   if(this.state.value == 'news')
      return <Text>data</Text>;
   return null;
}

render() {
    return (   
        <View style={styles.container}>
            { this.renderElement() }
        </View>
    )
}

Example 4: inline if in html component

Condition ? Block_For_True : Block_For_False

Example 5: react if statement

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