Skip to content

Commit 827b168

Browse files
Unregistering the auth observer when the component unmounts.
1 parent 61fdab5 commit 827b168

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

example/src/App.jsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,16 @@ class App extends React.Component {
5656
* @inheritDoc
5757
*/
5858
componentDidMount() {
59-
firebaseApp.auth().onAuthStateChanged((user) => {
60-
this.setState({signedIn: !!user});
61-
});
59+
this.unregisterAuthObserver = firebaseApp.auth().onAuthStateChanged(
60+
(user) => this.setState({signedIn: !!user}
61+
);
62+
}
63+
64+
/**
65+
* @inheritDoc
66+
*/
67+
componentWillUnmount() {
68+
this.unregisterAuthObserver();
6269
}
6370

6471
/**

0 commit comments

Comments
 (0)