diff options
author | Vitaly Takmazov | 2019-10-29 17:18:52 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2023-01-13 10:37:55 +0300 |
commit | 713566a435fea6c00cbd2e37d7c8c2a54ef2895d (patch) | |
tree | 92f86c7bed9c7bf2568b47ec3277a26190b5076c /vnext/src/ui | |
parent | 8f9a945990b403ebc673f79be925c0fd3737105c (diff) |
Fix UserInfo avatar update
Diffstat (limited to 'vnext/src/ui')
-rw-r--r-- | vnext/src/ui/UserInfo.js | 41 |
1 files changed, 18 insertions, 23 deletions
diff --git a/vnext/src/ui/UserInfo.js b/vnext/src/ui/UserInfo.js index 6310b8b7..29bf426f 100644 --- a/vnext/src/ui/UserInfo.js +++ b/vnext/src/ui/UserInfo.js @@ -1,4 +1,4 @@ -import React, { useState, useEffect } from 'react'; +import React, { useState, useEffect, useRef } from 'react'; import { Link } from 'react-router-dom'; import { info, fetchUserUri } from '../api'; @@ -23,20 +23,17 @@ export default function UserInfo(props) { }; const [user, setUser] = useState(currentUser); const { onUpdate } = props; + const userRef = useRef(user); useEffect(() => { isMounted = true; - setUser(previous => { - if (!previous.avatar) { - info(previous.uname).then(response => { - if (isMounted) { - onUpdate && onUpdate(response.data); - return response.data; - } - }); - } - return previous; - }); - + if (!userRef.current.avatar) { + info(userRef.current.uname).then(response => { + if (isMounted) { + onUpdate && onUpdate(response.data); + setUser(response.data); + } + }); + } return () => { isMounted = false; }; @@ -103,18 +100,16 @@ const UserSummary = React.memo(Summary); */ export function UserLink(props) { const [user, setUser] = useState(props.user); + const userRef = useRef(user); useEffect(() => { isMounted = true; - setUser(previous => { - if (previous.uri) { - fetchUserUri(previous.uri).then(response => { - if (isMounted) { - return response.data; - } - }); - } - return previous; - }); + if (userRef.current.uri) { + fetchUserUri(userRef.current.uri).then(response => { + if (isMounted) { + setUser(response.data); + } + }); + } return () => { isMounted = false; }; |