jsx if block 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: jsx if block

render () {
  return (
    
{(() => { if (someCase) { return (
someCase
) } else if (otherCase) { return (
otherCase
) } else { return (
catch all
) } })()}
) }

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

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

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

Tags:

Misc Example