Skip to content

Commit

Permalink
fix(FirestoreProvider): Added prop to use timestamps in snapshots for…
Browse files Browse the repository at this point in the history
… Firestore > v5.5.0 (#32)
  • Loading branch information
lucacasonato authored and green-arrow committed Nov 12, 2018
1 parent dafa65a commit c5dbbbc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ At the top level of your app, configure `firebase` and render the
If you're using [create-react-app][create-react-app], your `index.js`
file would look something like this:


```jsx
import React from 'react';
import ReactDOM from 'react-dom';
Expand All @@ -108,6 +109,11 @@ ReactDOM.render(
);
```

_Important: Starting with Firebase v5.5.0 timestamp objects stored in Firestore get returned as Firebase
Timestamp objects instead of regular Date() objects. To make your app compatible with this
change, add the `useTimestampsInSnapshots` to the FirestoreProvider element. If you dont do this
your app might break. For more information visit [the Firebase refrence documentation][https://firebase.google.com/docs/reference/js/firebase.firestore.Timestamp]._

_Note: The reason for the separate imports for `@firebase/app` and `@firebase/firestore`
is because `firestore` is not included in the default `firebase` wrapper package. See
the [firestore package](https://www.npmjs.com/package/@firebase/firestore) for more details._
Expand Down
7 changes: 6 additions & 1 deletion src/FirestoreProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ export default class FirestoreProvider extends Component {
static propTypes = {
firebase: PropTypes.object.isRequired,
children: PropTypes.node.isRequired,
useTimestampsInSnapshots: PropTypes.bool.isRequired
};

static defaultProps = {
useTimestampsInSnapshots: false
}

static childContextTypes = {
firestoreDatabase: PropTypes.object.isRequired,
firestoreCache: PropTypes.object.isRequired,
Expand All @@ -19,7 +24,7 @@ export default class FirestoreProvider extends Component {
const { firebase } = props;

this.state = {
firestoreDatabase: firebase.firestore(),
firestoreDatabase: firebase.firestore({timestampsInSnapshots: this.props.useTimestampsInSnapshots}),
firestoreCache: new FirestoreCache(),
};
}
Expand Down

0 comments on commit c5dbbbc

Please # to comment.