|
Answer» The map function is USED to show a LIST of elements in an array. It can be used in React Native like the following example: Example import React, { Component } from "react";
import { Text, View } from "react-native";
export default class mapFunction EXTENDS Component {
constructor(props) {
SUPER(props);
this.state = {
array: [
{
title: "example title 1",
subtitle: "example subtitle 1"
},
{
title: "example title 2",
subtitle: "example subtitle 2"
},
{
title: "example title 3",
subtitle: "example subtitle 3"
}
]
};
}
list = () => {
return this.state.array.map(element => {
return (
<View style={{ margin: 10 }}>
<Text>{element.title}</Text>
<Text>{element.subtitle}</Text>
</View>
);
});
};
render() {
return <View>{this.list()}</View>;
}
}
|