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

Do I understand correctly why the <select> value doesn't change?

Here’s the sandbox

It doesn’t change because the array options stays the same even though indexOf gets a new argument value?

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 :

The main reason your select won’t show the selected value is because you’re setting the value to the index of the array, not the value itself.

For example, value needs to be high, not index 0, so simply change the select to:

<select
    value={value.metrics}
    onChange={(e) => setValue({ ...value, metrics: e.target.value })}
>

Updated CodeSandBox
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