Are you first timer at lazacode.org? Why not join us and start exchange your programming knowledge with everyone. Register today!

React - conditional example

0 votes
98 views
added Jul 6, 2020 in React by LC Marshal Captain (25,860 points)
const listingStreet = data.field_prop_street_t
    ? data.field_prop_street_t
    : '';
  const listingDistrict = data.district_s_lower ? data.district_s_lower : '';
  const listingState = data.state_s_lower ? data.state_s_lower : '';
  const fullAddress = `${listingStreet ? `${listingStreet}, ` : ''}${
    listingDistrict ? `${listingDistrict}, ` : ''
  }${listingState ? `${listingState}` : ''}`;

 

<p className="listing-address">
  {/* {listingStreet}, {listingDistrict}, {listingState} */}
  {fullAddress}
</p>

 

4 Responses

0 votes
responded Apr 12 by lcjr Second Warrant Officer (5,360 points)
{!isShowMore && agentDesc.length > 40 && (
  <div>
    <button
      type="button"
      className="btn btn-link show-more-button"
      onClick={onShowMore}
    >
      Show More
    </button>
  </div>
)}

 

0 votes
responded Apr 12 by lcjr Second Warrant Officer (5,360 points)
var loginButton;
if (loggedIn) {
  loginButton = <LogoutButton />;
} else {
  loginButton = <LoginButton />;
}

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

 

0 votes
responded Apr 12 by lcjr Second Warrant Officer (5,360 points)
literal else if condition

{agentURL && (
  <div className="text-secondary url-present"> 
  <span className="agency-name">{agencyName}</span>
  <span className="agent-id">{agentID}</span>
  <span>
    <a className="agent-url" target="_blank" href={`http://${agentURL}`}>{agentURL}</a>
  </span>
  </div>
)}
{!agentURL && (
  <div className="text-secondary"> 
  <span className="agency-name">{agencyName}</span>
  <span className="agent-id">{agentID}</span>
  </div>
)}

 

0 votes
responded Apr 20 by lcjr Second Warrant Officer (5,360 points)
{!!ListingId && (
  <>
    <div className="col-md-6 detail-col">
      <div className="detail-label">Listing ID</div>
      <div className="detail-data">{ListingId}</div>
    </div>
  </>
)}
{PropType != 33 && !!LandArea && (
  <>
    <div className="col-md-6 detail-col">
      <div className="detail-label">Land Area</div>
      <div className="detail-data">{landAreaTxt}</div>
    </div>
  </>
)}

 

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...