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

why is there an error when selecting data in the picker?

   <Picker
      selectedValue={data}
      onValueChange={itemValue => setdata(itemValue)}>
      <Picker.Item label="Pilih Bencana" value="" />
      {data &&
        data?.map((item, key) => {
          return (
            <Picker.Item label={item.bencana} value={item.ID} key={key} />
          );
        })}
    </Picker>

The code above can display data, but when the data is selected an error like this occurs undefined is not a function (near '...data.map...') where to fix?

>Solution :

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

That because you setdata with onValueChange props, and the itemValue are not an array anymore.

.map work only with array

https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Global_Objects/Array/map

You have to use another React.useState to keep item value save ‘itemValue’ to use it and show there

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