Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

If clause in JSX map function

So i have this code to generate multiple dropdown lists.

<div>
  {['Mischung', 'Menge'].map((key) => (
    <select key={key}>
      {mischung.map(({ [key]: value }) => (
        <option key={value}>{value}</option>
      ))}
    </select>
  ))}
</div>

Every dropdown list is beeing generated, but with empty values.

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

enter image description here

As you can see there are empty values from the other dropdown.

How can i check the value for null or if its not empty.

>Solution :

<div>
  {['Mischung', 'Menge'].map((key) => (
    <select key={key}>
      {mischung.map(({ [key]: value }) => {
        if (value) {
          return (
            <option key={value}>{value}</option>
          )}
        }
      )}
    </select>
  ))}
</div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading