React - wrap react element with react frament <>

0 votes
125 views
added Apr 20, 2021 in React by lcjr First Warrant Officer (11,530 points)

Need to wrap HTML & JS in div to write code, but you don't need one. Instead, use react frament <>your code</>.


const agentNumber = get(data, 'agent_contact_s_lower', '');
  const resultCallForPrice = get(data, 'call_for_price', '');
  let callForPriceCheck;
  if (resultCallForPrice === 'yes') {
    callForPriceCheck = (
      <>
        <a href={`tel:${agentNumber}`}>Call for price</a>
      </>
    );
  } else {
    callForPriceCheck = <>{accounting.formatMoney(listingPrice, 'RM ', 0)}</>;
  }
  
  return (
    <>
      <div className="mobile-view">
        <p className="card-price">{callForPriceCheck}</p>{' '}
      
      <div className="desktop-view">
        <p className="card-price">{callForPriceCheck}</p>{' '}
      
     </>

 

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