React Native FlatList with object
You can do it by
<Flatlist
data={Object.values(obj)}
...
/>
you can do like this way. check working snack. https://snack.expo.io/@nazrdogan/bad-cashew
import * as React from 'react';
import { Text, View, StyleSheet, FlatList } from 'react-native';
import { Constants } from 'expo';
// You can import from local files
import AssetExample from './components/AssetExample';
// or any pure javascript modules available in npm
import { Card } from 'react-native-paper';
var obj = {
'Lisa.Sky': {
name: 'Lisa',
surname: 'Sky',
age: 21,
sex: 'female',
},
'Thomas.Prat': {
name: 'Thomas',
surname: 'Prat',
age: 33,
sex: 'male',
},
'Paul.Sing': {
name: 'Paul',
surname: 'Sing',
age: 88,
sex: 'male',
},
'Andrew.Brown': {
name: 'Andrew',
surname: 'Brown',
age: 23,
sex: 'male',
},
};
export default class App extends React.Component {
render() {
return (
<View style={styles.container}>
<FlatList
data={Object.keys(obj)}
renderItem={({ item }) => <Text>{obj[item].name}</Text>}
/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
paddingTop: Constants.statusBarHeight,
backgroundColor: '#ecf0f1',
padding: 8,
},
});