react if condition code example

Example 1: ternary operator react

render () {
  return (
    
{ //Check if message failed (this.state.message === 'failed') ?
Something went wrong
:
Everything in the world is fine
}
); }

Example 2: if else react render in jsc

const functionalComponent=()=> {

  return (
    
{ props.isFeatured ? (
lol
) : ("") }
); }

Example 3: if else render react

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

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

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

render() {
    return (   
        
            { this.renderElement() }
        
    )
}

Example 5: adding a if stement in jsx

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

Example 6: inline if in html component

Condition ? Block_For_True : Block_For_False

Tags:

Misc Example