react flat list code example
Example 1: how to use flatlist keyextractor
<FlatList
data={[{name: 'a'}, {name: 'b'}]}
renderItem={
({item}) => <Text>{item.name}</Text>
}
keyExtractor={(item, index) => index.toString()}
/>
Example 2: flatlist like in reactjs
There is no specific component like it is in react-native to do this kind of stuff, so I usually just use map() to achieve this kind of things.
But if it is reusable you can surely create a List component for yourself so that you don't write map() function each time for the same list.
Kind of like this:
function Item(props) {
return <li>{props.value}</li>;
}
function MyList(items) {
return (
<ul>
{items.map((item) => <Item key={item.key} value={item} />)}
</ul>
);
}