Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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>
    )
}
Comment

react if statement

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

if else jsx

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

if or react

// Before your return / render block you could write something like this:
const ifThisOrThat = ifThis || ifThat;

// then you can use it in your return / render block like so:
{ ifThisOrThat &&
	<p>I will render ifThis or ifThat is true!</p>
}
Comment

jsx else if statement

render() {
  return <span>
    {this.props.conditionA ? "Condition A" 
      : this.props.conditionB ? "Condition B" 
      : "Neither"}
  </span>;
}
Comment

if else react render in jsc

const functionalComponent=()=> {

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

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

make a if in jsx

var loginButton;
if (loggedIn) {
  loginButton = <LogoutButton />;
} else {
  loginButton = <LoginButton />;
}

return (
  <nav>
    <Home />
    {loginButton}
  </nav>
);
Comment

react js if statement

if (coinToss() === 'heads') {
  img = <img src={pics.kitty} />
} else {
  img = <img src={pics.doggy} />
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: redux saga fetch data using axios 
Javascript :: cors axios 
Javascript :: javascript last element array 
Javascript :: google tuner 
Javascript :: on button click show collapse div jquery 
Javascript :: console.log 
Javascript :: javascript formdata 
Javascript :: js get datatable attr value on click 
Javascript :: js check if image url exists 
Javascript :: Node.JS mongodb create database 
Javascript :: new Map() collection in react state 
Javascript :: event.propagation not working 
Javascript :: killall node 
Javascript :: import npm module node.js 
Javascript :: react onchange multiple functions 
Javascript :: how to delete object properties in javascript 
Javascript :: paragraph to single line in javascript 
Javascript :: vue js get routes 
Javascript :: adding element to array javascript 
Javascript :: react router reload page not found 
Javascript :: round to 2 decimal places 
Javascript :: .shift javascript 
Javascript :: variables javascript 
Javascript :: react get route params 
Javascript :: how manipulate the multiple input option data in one function in vue js 
Javascript :: yarn globakl 
Javascript :: javascript apply 
Javascript :: javascript string add new line 
Javascript :: javascript set cookie 
Javascript :: js append zeros 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =