Am actively creating a react native app for my college studies ! In that am using external api as data source. The problem am facing is that sometimes am getting data in single object and sometimes its in array format. How to handle this in react native perspective ?
As am maping jsx considering it as array but when i get object it throws error
My data example:
const data = { // this is example of single object
entry: {
key: "0",
value: "Patrik"
}
}
const data = { // this is example of array
entry: [
{
key: "0",
value: "Patrik"
},
{
key: "1",
value: "John"
}],
}
So this is how i get data from external api, and now my react native jsx code:
{ data.entry.map(o => {
<View key={o.key}>
<View style={{ paddingLeft: 25 }}>
<Text style={{ fontWeight: 'bold' }}>{o.value}</Text>
</View>
</View>
})
}
So, when i get array, it works but when i get object this throws error ! Any help on this ?