<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?
CodePudding user response:
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