React - conditional rendering as per value

0 votes
97 views
added Feb 22 in React by lcjr First Warrant Officer (11,560 points)

If apiResponseValue is equal to 0, <OkListing /> should be shown and <ContactFormComponent /> should be hidden, and vice versa. Here's how you can achieve it: 

 

const [apiResponseValue, setApiResponseValue] = useState(0);

// From this 
<div className="contact-box-form">
  <ContactFormComponent
    isMobile={true}
    ContactFormData={ContactFormData}
    listingProperties={listingProperties}
    // resp={resp}
    isContacted={false}
    AddWebAnalytics={AddWebAnalytics}
    noWhatsApp={noWhatsApp}
    onlyWhatsapp={onlyWhatsapp}
    origin="list"
  />
  {apiResponseValue === 0 && <OtpListing />}
</div>
     
// To this   
<div>
  {apiResponseValue === 0 ? <OkListing /> : (
    <ContactFormComponent
      isMobile={true}
      ContactFormData={ContactFormData}
      listingProperties={listingProperties}
      // resp={resp}
      isContacted={false}
      AddWebAnalytics={AddWebAnalytics}
      noWhatsApp={noWhatsApp}
      onlyWhatsapp={onlyWhatsapp}
      origin="list"
    />
  )}
</div>

 

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