Skip to content

Commit bde2346

Browse files
committed
Fix layout profile
1 parent 51aeb68 commit bde2346

File tree

1 file changed

+23
-24
lines changed

1 file changed

+23
-24
lines changed

src/screens/Profile.js

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,40 +10,39 @@ export default function ProfileScreen() {
1010

1111
const [user, setUser] = useState(null);
1212

13+
let unsubscribe = null;
14+
1315
useEffect(() => {
14-
profile();
15-
// unsubscribe();
16-
}, []);
16+
console.log('componentDidMount');
17+
18+
unsubscribe = firebase
19+
.firestore()
20+
.collection('users')
21+
.doc(_uid())
22+
.onSnapshot(
23+
doc => {
24+
// console.log(doc.data());
25+
setUser(doc.data());
26+
},
27+
err => {
28+
console.log(err);
29+
},
30+
);
1731

18-
// let unsubscribe = firebase
19-
// .firestore()
20-
// .collection('users')
21-
// .doc(_uid())
22-
// .onSnapshot(doc => {
23-
// console.log(doc.data());
24-
// setUser(doc.data());
25-
// });
32+
return () => {
33+
console.log('componentWillUnmount');
34+
unsubscribe();
35+
};
36+
}, []);
2637

2738
function _onLogout() {
2839
// NOTE: context
29-
// _logout();
40+
_logout();
3041

3142
// NOTE: firebase
32-
// unsubscribe();
3343
firebase.auth().signOut();
3444
}
3545

36-
function profile() {
37-
firebase
38-
.firestore()
39-
.collection('users')
40-
.doc(_uid())
41-
.onSnapshot(doc => {
42-
// console.log(doc.data());
43-
setUser(doc.data());
44-
});
45-
}
46-
4746
function _uid() {
4847
return (firebase.auth().currentUser || {}).uid;
4948
}

0 commit comments

Comments
 (0)