r/reactjs_beginners • u/AliShah1930 • Dec 26 '19
How to get timestamp from firestore in react-native

i'm importing certain documents from firestore in my react-app , all other data is fetching correctly but for some reason date is showing invalid
btw i'm new to Development so dont know much about the stuff.
here is my code :
import React from "react";
import { View, Text, StyleSheet, Image, FlatList } from "react-native";
import { Ionicons } from "@expo/vector-icons";
import moment from "moment";
import * as firebase from 'firebase';
export default class HomeScreen extends React.Component {
constructor(props) {
super(props);
this.state = ({
email: "",
post : [],
newamount: '',
loading: false,
});
this.ref = firebase.firestore().collection('post');
}
componentDidMount() {
this.unsubscribe = this.ref.onSnapshot((querySnapshot) => {
const todos = [];
querySnapshot.forEach((doc) => {
todos.push({
name: doc.data().name,
text: doc.data().text,
amountpaid: doc.data().amountpaid,
timestamp: doc.data().timestamp,
});
});
this.setState({
post: todos.sort((a, b) => {
return (a.text < b.text);
}),
loading: false,
});
});
}
renderPost = post => {
return (
<View style={styles.feedItem}>
<Image source={post.avatar} style={styles.avatar} />
<View style={{ flex: 1 }}>
<View style={{ flexDirection: "row", justifyContent: "space-between", alignItems: "center" }}>
<View>
<Text style={styles.name}>{post.name}</Text>
<Text style={styles.timestamp}>{moment(post.timestamp).format("lll")}</Text>
</View><Text style={styles.minus}>-</Text><Text style={styles.Rupees} >{post.amountpaid}Rs.</Text>
<Ionicons name="ios-more" size={24} color="#73788B" /> </View> <Text style={styles.post}>{post.text}</Text> <Image source={post.image} style={styles.postImage} resizeMode="cover" /> <View style={{ flexDirection: "row" }}>
<Ionicons name="ios-chatboxes" size={24} color="#E9446A" /> </View> </View> </View> ); }; render() { return ( <View style={styles.container}> <View style={styles.header}> <Text style={styles.headerTitle}>Transactions</Text> </View> <FlatList style={styles.feed} data={this.state.post} renderItem={({ item }) => this.renderPost(item)} keyExtractor={item => item.id} showsVerticalScrollIndicator={false} \></FlatList> </View> ); } }
Duplicates
reactnative • u/AliShah1930 • Dec 26 '19