aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--vnext/src/ui/UserInfo.js41
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;
};