I've looked at some similar question and tried to change the code but the data still won't show. I've watch a few tutorials and I've got this far. This is my code.
export default class HomeScreen extends React.Component {
state = {
dateItems: [],
loading: false,
}
unsubscribe = null;
async getAppointment() {
const dateList = [];
var snapshot = await firebase.firestore()
.collection('appointment')
.orderBy('createdAt', 'desc')
.get()
snapshot.docs.forEach(doc => {
dateList.push({
key: doc.id,
date: doc.data().date,
createdAt: doc.data().createdAt,
});
this.setState({
dateItems: dateList,
loading: false,
});
});
console.log(dateList);
}
componentDidMount() {
this.getAppointment();
}
render() {
return (
<View style={styles.container}>
<View >
<View style={styles.header}>
<Text style={styles.headerTitle}>Appointments</Text>
<Button
onPress={() => this.props.navigation.navigate('Booking')} title="Add"
/>
</View>
<FlatList
data={this.state.dateItems}
renderItem={(item, index) => (
<View>
<Text style={styles.item}>{item.date}</Text>
<Text>Created: {item.createdAt}</Text>
<View style={styles.hr}></View>
</View>
)}
keyExtractor={item => item.id}
/>
</View>
</View>
);
}
}
The data shows in an array in the console
Array [
Object {
"createdAt": t {
"nanoseconds": 467000000,
"seconds": 1591023433,
},
"date": t {
"nanoseconds": 478000000,
"seconds": 1592740813,
},
"key": "Qlaq8Nd5GYaxFYr9M6Iq",
},
Object {
"createdAt": t {
"nanoseconds": 31000000,
"seconds": 1591020391,
},
"date": t {
"nanoseconds": 859000000,
"seconds": 1593327612,
},
"key": "ZsP2pBcNNgb4Nj6Jrpce",
},
]
I need to show the date and not the timestamp for both date and createdAt. i don't know where I can implement this.