javascript - Using an if/else inside react render return -


i have javascript inside react render:

  <p id='canplay'>           {this.state.canplayarray.map(function(num, index){             return <p key={ index }>name: {num.name} date indicated: {num.dateconfirmed}</p>;           }, this)}    </p> 

however sometimes, canplayarray may empty. how can if array.length >0 render array else display 'no 1 has responded'

i cant if/else inside html dont think , before return() have:

if (this.state.info){       output = <thanks />;     } 

which may stop me doing if/else there?

thinking of using ternary operator not sure put it

<p id='canplay'>   {     this.state.canplayarray.length     ? this.state.canplayarray.map(function(num, index){       return <p key={ index }>name: {num.name} date indicated: {num.dateconfirmed}</p>;     }, this)     : <p>no 1 has responded</p>   } </p> 

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -