简体   繁体   中英

react native flatlist with firebase

rendering :

<FlatList
    data={this.state.data}
    renderItem={({ item }) => 
    <Text style={styles.item}>{item.key}</Text>}
/>

my method :

displayCollectionUser().then((collection) => {
    this.setState({
        data: Object.values(collection)
    });
    console.log("this.state.data");
    console.log(this.state.data);
});

Problem: children not display 在此处输入图片说明

在此处输入图片说明

Hello your data from FlatList has to be an Array . Your response is an Object .

this.state.data has to be an array. You can change your response to be an array, or move the object properties to an array. Just use this :

this.setState({
  data: Object.values(collection)
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM