React - if element is empty or not present

0 votes
190 views
added Jun 28, 2021 in React by lcjr First Warrant Officer (11,970 points)
const wolfBoxes = data?.result?.field_prop_wolfboxes?.und?.[0]?.value ?? '';

{wolfBoxes && (
  <div className="detailItem"> 
      <span>
        <img
        src="/images/wolfbox.png" 
        css={css`
        width: 19px;
        height: 19px;
      `}
      alt="wolf box"
      />
    </span>
    <span>{`${wolfBoxes} boxes`}</span> 
  </div>
)}

 

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