Skip to content

Commit 4cf6799

Browse files
Tweak README text
1 parent 153780b commit 4cf6799

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

README.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,16 @@ class MyComponent extends React.Component {
5858
};
5959

6060
componentDidMount() {
61-
this.deregisterAuthObservable = firebase.auth().onAuthStateChanged((user) => {
61+
// Updating the `isSignedIn` and `userProfile` local state attributes when the Firebase Auth
62+
// state changes.
63+
this.unregisterAuthObserver = firebase.auth().onAuthStateChanged((user) => {
6264
this.setState({ isSignedIn: !!user, userProfile: user });
6365
});
6466
}
6567

6668
componentWillUnmount() {
67-
this.deregisterAuthObservable();
69+
// Un-registers the auth state observer.
70+
this.unregisterAuthObserver();
6871
}
6972

7073
// ...
@@ -74,7 +77,7 @@ class MyComponent extends React.Component {
7477

7578
### Firebase Realtime Database
7679

77-
Here is an example of how you can map data from the Realtime Databaseto your React component's local state:
80+
Here is an example of how you can map data from the Realtime Database to your React component's local state:
7881

7982
```js
8083
import firebase from './firebase.js';
@@ -118,7 +121,7 @@ class MyComponent extends React.Component {
118121

119122
componentDidMount() {
120123
// Updating the `someCollection` local state attribute when the Cloud Firestore 'someCollection' collection changes.
121-
this.unsubscribeCollectionObserver = firebase.firestore().collection('someCollection').onSnapshot((snap) => {
124+
this.unregisterCollectionObserver = firebase.firestore().collection('someCollection').onSnapshot((snap) => {
122125
const someCollection = {};
123126
snap.forEach((docSnapshot) => {
124127
someCollection[docSnapshot.id] = docSnapshot.data();
@@ -127,15 +130,15 @@ class MyComponent extends React.Component {
127130
});
128131

129132
// Updating the `someDocument` local state attribute when the Cloud Firestore 'someDocument' document changes.
130-
this.unsubscribeDocumentObserver = firebase.firestore().doc('/collection/someDocument').onSnapshot((snap) => {
133+
this.unregisterDocumentObserver = firebase.firestore().doc('/collection/someDocument').onSnapshot((snap) => {
131134
this.setState({ someDocument: snap.data() });
132135
});
133136
}
134137

135138
componentWillUnmount() {
136139
// Un-register the listeners.
137-
this.unsubscribeCollectionObserver();
138-
this.unsubscribeDocumentObserver();
140+
this.unregisterCollectionObserver();
141+
this.unregisterDocumentObserver();
139142
}
140143

141144
// ...
@@ -144,7 +147,7 @@ class MyComponent extends React.Component {
144147

145148
### Updating data
146149

147-
When updating data, do not set the local state. Setting the local state will not update Firebase. Instead you should update your data on Firebase directly, this will trigger any observers that you have setup locally instantly from cache.
150+
When updating data, do not modify the local state directly. Modifying the local state will not update the data on Firebase. Instead you should only update your data on Firebase, this will trigger any observers that you have setup locally instantly from cache.
148151

149152
For instance, let's take an app that has a list of todo items stored on Firebase. It also has a text field and a button to add new todos:
150153

0 commit comments

Comments
 (0)