I am rendering a array of data. It works fine with map function but if I try to call item wise it gives an error. Undefined is not an object (evaluating 'data[0].uri')
This doesn't work
render () {
const data = this.state.data;
const selectedIndex = this.state.selectedIndex;
return (
<View style={styles.text}>
<Card
title="Profiling Question "
image={{ uri: data[0].uri }}
>
<Text style={{ marginBottom: 10 }}>
{data[0].text}
</Text>
<Button
onPress={this.updateIndex}
/>
</Card>
</View>
);
}
but this works fine:
return (
<View style={styles.text}>
{data.map((item) => {
return (
<Card
title="Profiling Question "
image={{ uri: item.question_image }}
>
<Text style={{ marginBottom: 10 }}>
{item.question_text}
</Text>
<Button
onPress={this.updateIndex}
/>
</Card>
)})}
</View>
);
I wish to render only ONE item at a time on screen. Once user clicks button then second item renders.
data[0]? are you making any api call to update it?