Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

first base.syncState() works but one immediately after does not #268

Open
yamini-krishnamurthy opened this issue Apr 23, 2019 · 0 comments

Comments

@yamini-krishnamurthy
Copy link

yamini-krishnamurthy commented Apr 23, 2019

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant