Querying for Most Recent Firestore Documents with React-Redux-Firebase
Sometimes you want to query for the most recent firestore documents in a certain collection. In my case I wanted to display all documents that were created less than 20 minutes ago. Here is how I did it.
Prepping Firestore Documents
First, add a “created” field to the documents in the interested collection using firestore.Timestamp.now()
Syncing Redux Store with Firestore
Then add a useFirestoreConnect to the relevant component in order to keep the redux state in sync with firebase. Notice how we add the queryParams to order by value and take the first 10 documents.