I've got a little bit problem with sorting posts by the time of adding a post in React and Firebase. I think the easiest solution is to add a timestamp
property but I don't want to do it. Is it any other way to do this?
import { useEffect, useState } from 'react';
import './Post.css';
import Post from './Post';
import Profile from './Profile';
import db from './firebase';
const Content = () => {
const [posts, setPosts] = useState([]);
useEffect(() => {
db.collection('posts').onSnapshot(snapshot => (
setPosts(snapshot.docs.map(doc => doc.data()))
))
}, [])
return (
<div className="feed">
<div className="feed__header">
<h2>Home</h2>
</div>
<Profile />
{posts.map(post => (
<Post
key={post.text}
name={post.name}
surname={post.surname}
text={post.text}
/>
))}
</div>
)
}
export default Content;
If something is unclear feel free to ask :)