Skip to content

Commit 61fdab5

Browse files
Tweaking sample code in Readme to make sure we unregister the listeners when the component unmounts.
1 parent 348e70e commit 61fdab5

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class SignInScreen extends React.Component {
106106

107107
// The component's Local state.
108108
state = {
109-
signedIn: false // Local signed-in state.
109+
iSignedIn: false // Local signed-in state.
110110
};
111111

112112
// Configure FirebaseUI.
@@ -126,10 +126,15 @@ class SignInScreen extends React.Component {
126126

127127
// Listen to the Firebase Auth state and set the local state.
128128
componentDidMount() {
129-
firebase.auth().onAuthStateChanged(
130-
(user) => this.setState({signedIn: !!user})
129+
this.unregisterAuthObserver = firebase.auth().onAuthStateChanged(
130+
(user) => this.setState({isSignedIn: !!user})
131131
);
132132
}
133+
134+
// Make sure we un-register Firebase observers when the component unmounts.
135+
componentWillUnmount() {
136+
this.unregisterAuthObserver();
137+
}
133138

134139
render() {
135140
if (!this.state.signedIn) {

0 commit comments

Comments
 (0)