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

how can i add a default select option from a mapped API call

Hey guys im grabbing data from a car query API, i am then listing the latest 40 years as buttons but adding the remaining years as a select option, however i on the select i want to add a default unselectable option for "–select a year–"

here is the code:


<select className="appearance-none text-center p-4 w-full text-md font-semibold leading-none bg-dark-purple text-white border-light-purple rounded outline-none" name="field-name" placeholder="Select another year" id="selectYears" option>
  {remainingYears.map((data, index) => { if (latestYear - data.year > 29) { return (
  <option key={data.year} value={data.year}>
    {data.year}
  </option>
  ); } })}
</select>

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

>Solution :

Just include the default options outside of the .map() using this pattern:

<select>
  <option selected disabled>Default</option>
  {[].map(data => <option>Real options</option>)}
</select>
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