first base.syncState() works but one immediately after does not
yamini-krishnamurthy opened this issue · 0 comments
yamini-krishnamurthy commented
This is how my state looks:
this.state = {
fullness: 6,
count: 1,
lastFed: this.props.startDate,
}
This is what my componentDidMount (kind of) looks like:
componentDidMount() {
this.fullnessRef = base.syncState(`users/${this.props.uid}/fullness`, {
context: this,
state: 'fullness',
})
this.lastFedRef = base.syncState(`users/${this.props.uid}/lastFed`, {
context: this,
state: 'lastFed',
})
if(this.props.newUser === false) {
const hoursPassed = new Date() - this.state.lastFed
const reduceFullnessBy = Math.floor(hoursPassed / (1000 * 60))
const fullness = this.state.fullness -
reduceFullnessBy
this.setState({ fullness })
}
}
I see users/uid/fullness appear on firebase, but users/uid/lastFed (a Date) will not appear. In fact, when I use React dev tools, this.state.lastFed becomes undefined all of a sudden. Not entirely sure what I'm doing wrong. Does syncState not work with Date objects?