To create a list in React Native where each row displays an image of a ticket, you can follow the steps below:
import { View, FlatList, Image } from 'react-native';
const ticketData = [
{
id: 1,
imageSrc: require('./ticket1.png'),
},
{
id: 2,
imageSrc: require('./ticket2.png'),
},
// ... add more tickets here
];
const TicketItem = ({ ticket }) => (
<View>
<Image source={ticket.imageSrc} />
</View>
);
const App = () => (
<View>
<FlatList
data={ticketData}
renderItem={({ item }) => <TicketItem ticket={item} />}
keyExtractor={(item) => item.id.toString()}
/>
</View>
);
In this code snippet, we pass the ticketData
array to the data
prop of the FlatList
, and specify a renderItem
function to render each row of the list. We also use the keyExtractor
prop to extract a unique key for each item, which is necessary for React to efficiently update the list when it changes.
By following these steps, you can create a list in React Native where each row displays an image of a ticket.
Asked: 2023-05-28 03:17:56 +0000
Seen: 1 times
Last updated: May 28 '23