Issue
const Sub_Map = () => {
const [isLoading, setLoading] = useState();
const [data, setdata] = useState();
useEffect(() => {
getData();
}, []);
const getData = () => {
fetch('http://. . . . /aplikasi/restapi.php?op=getJenis')
.then(res => res.json())
.then(json => setdata(json))
.catch(error => alert(error))
.finally(setLoading(false));
};
on the "data.map" there is an error, please explain for me
return (
<View style={styles.container}>
<Text style={styles.text}>Pilih Data</Text>
<View style={styles.picker}>
{isLoading ? (
<ActivityIndicator />
) : (
<Picker
selectedValue={data}
onValueChange={itemValue => setdata(itemValue)}>
{data.map((item, key) => {
<Picker.Item
label={'${item.bencana}'}
value={'${ item.id }'}
key={key}
/>;
})}
</Picker>
)}
</View>
);
};
please help me, i'm still newbie about react native TypeError: undefined is not an object (evaluating 'data.map')
Solution
Write it like this, and it will work:
{data && data?.map((item, key) => { ...
Answered By - Alija Fajić
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.