but when i display data by using console.log it display properly import React,{useState,useEffect,Component} from 'react'; import {StyleSheet,View,Text,TextInput,TouchableOpacity, Button, FlatList} from 'react-native'; import { DataTable } from 'react-native-paper'; import {fire} from '../config/fire'; import { ListItem, SearchBar } from 'react-native-elements'; function Donorlist(){ const[Donors,setDonors]=useState([]); const fetchDonors=async()=>{ const response=fire.firebase_.firestore().collection('Donors'); const data=await response.get(); data.docs.forEach(item=>{ setDonors([...Donors,item.data()]); //console.log("hI I AM IN DONORS FETCH LIST"); })
}
useEffect(()=>{
fetchDonors();
},[])
return (
<View>
<FlatList
data={Donors}
renderItem={({item})=>(
console.log(item.name),
<Text>
{item.name}
</Text> )}/>
{
/*
Donors.map((Donor,index)=>{
return(
console.log(Donor),
<View className="blog-container">
<Text>Donor List</Text>
<DataTable>
<DataTable.Header>
<DataTable.Title
style={{
width: 100, height: 100, backgroundColor: 'powderblue'
}} >Name</DataTable.Title>
<DataTable.Title
style={{
width: 100, height: 100, backgroundColor: 'powderblue'
}} >Email</DataTable.Title>
<DataTable.Title
style={{
width: 100, height: 100, backgroundColor: 'powderblue'
}} >Phone</DataTable.Title>
<DataTable.Title
style={{
width: 100, height: 100, backgroundColor: 'powderblue'
}} >Country</DataTable.Title>
<DataTable.Title
style={{
width: 100, height: 100, backgroundColor: 'powderblue'
}} >State</DataTable.Title>
<DataTable.Title >City</DataTable.Title>
<DataTable.Title
style={{
width: 100, height: 100, backgroundColor: 'powderblue'
}} >Pin</DataTable.Title>
</DataTable.Header>
<DataTable.Row>
<DataTable.Cell ><Text>{Donor.name}</Text></DataTable.Cell>
<DataTable.Cell >{Donor.email}</DataTable.Cell>
<DataTable.Cell >{Donor.phone}</DataTable.Cell>
<DataTable.Cell >{Donor.name}</DataTable.Cell>
<DataTable.Cell >{Donor.email}</DataTable.Cell>
<DataTable.Cell >{Donor.phone}</DataTable.Cell>
<DataTable.Cell >{Donor.phone}</DataTable.Cell>
</DataTable.Row>
<DataTable.Pagination
page={1}
numberOfPages={3}
onPageChange={page => {
console.log(page);
}}
label="1-2 of 6"
/>
</DataTable>
<View>
<Text>List Data</Text>
<Text>{Donors.name}</Text>
</View>
</View>
)
})*/
}
</View>
);
}
export default Donorlist;
extraData={Donors}
props in your Flatlist and then check. - Kishan Bharda