I am successfully querying Firestore documents with a timestamp earlier than the current date like so:
import React from 'react'
import CircularProgress from '@material-ui/core/CircularProgress'
import { useSelector } from 'react-redux'
import { useFirestoreConnect } from 'react-redux-firebase'
import Grid from '@material-ui/core/Grid'
function MeetingHistory({ userId }) {
const todaysDate = new Date()
useFirestoreConnect([
{ collection: 'users',
doc: userId,
subcollections: [{ collection: 'scheduled',
where: [
['date', '<', todaysDate],
]
}],
storeAs: `${userId}-history-scheduled`
}
])
const pastMeetings = useSelector(state => state.firestore.ordered[`${userId}-history-scheduled`])
if (!pastMeetings) return (
<Grid container direction='row' alignItems='center' justify='center'>
<CircularProgress />
</Grid>
)
console.log('meetings', pastMeetings)
return (
<div>
<p>I am going to render past meeting data here</p>
</div>
)
}
export default MeetingHistory
However, console.log('meetings', pastMeetings)
is printing constantly leading me to believe that since the current date is constantly updating as time passes, my database is getting queried every second. This makes sense seeing that new Date() is constantly changing, but I don't want this behavior. I am looking for a way to take a snapshot of the time that won't keep changing with time and base my query off that. Any solution to this would be greatly appreciated. My goal is simply to avoid querying as often as time passes.