I'm trying to build a simple app which will show a dropdown, the value of the dropdown gained from a fetch's return. Furthermore, I want to show the location only in the dropdown/picker/or any other component where I can pick 1 option.
Should I put the return in an array or anything?
When I console the return, it is like this
[
{
"ID": "BOGOR~10~522",
"Location": "BOGOR"
},
{
"ID": "JADETABEK~16~502",
"Location": "JADETABEK"
}
]
Here is the testing class
import React , { Component } from 'react';
import { View , StyleSheet , Text , Dimensions , Picker } from 'react-native';
import { Dropdown } from 'react-native-material-dropdown';
import { Item } from 'native-base';
const ScreenWidth = Dimensions.get('window').width;
const Screenheight = Dimensions.get('window').height;
export default class testing extends Component {
constructor(props) {
super(props)
this.state = {
data: []
}
}
componentDidMount() {
fetch(url, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({"lokasi":
{
}
})
})
.then(response => response.json())
.then(res => {
console.log(res.PilihLokasiResult.Lokasi)
this.setState({
data: res.PilihLokasiResult.lokasi
})
})
}
render() {
return(
<View style={styles.container}>
{this.state.data.map((index) => {
return(
<Dropdown/>
)
})}
</View>
)
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: 'white',
},
})
so now the data[] in the constructor has the value of the response like in the first box. but I don't know how to set the values of location to the dropdown item. can anyone help? thanks

dataprop as an array. So, you need to pass an array for the options. You can create this array from your fetch result. I can't understand your other question, related to the "location" one. If you can explain it more clearly maybe someone can help.Locationvalues from the response to pass theDropdowncomponent right?