I'm willing to parse the above JSON response to a FlatList, but I can't figure what I'm missing. Since it does not have a key and value pair, I'm not sure how to render it.
{"list":["a","b","c","d"]}
My code is...
import React from 'react';
import { View, FlatList, Text } from 'react-native';
export default class Home extends React.PureComponent {
constructor(props) {
super(props);
this.state = { dataSource: [] };
}
async componentDidMount() {
const response = await fetch('http://.../');
const responseJson = await response.json();
this.setState({ dataSource: responseJson.list });
}
render() {
return (
<View style={{ flex: 1, paddingTop: 20 }}>
<FlatList
data={this.state.dataSource}
renderItem={({ item, index }) => <Text>{item[index]}</Text>}
keyExtractor={(item, index) => index}
/>
</View>
);
}
}
this.setState({ dataSource: responseJson.lista });you don't have any property namedlistain your jsonrenderItem={({ item, index }) => <Text>{item[index]}</Text>}facebook.github.io/react-native/docs/flatlist