swami swami - 3 months ago 19
React JSX Question

javascript jsx map on result of logical or

I want to have an expression like:

<td>
{phones.map((phone, j) =>
<p>{this.renderPhone(phone)}</p>
)}
</td>


but phones array may not always be defined.

Is there something like this possible:

(phones || []).map()

Answer

you can check it like below,

const self = this;
 <td>
   {phones !== undefined ? phones.map((phone, j) => 
     <p>{this.renderPhone(phone)}</p>
     )
   : null}
 </td>
Comments