diff options
Diffstat (limited to 'vnext/src/ui/UserInfo.js')
-rw-r--r-- | vnext/src/ui/UserInfo.js | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/vnext/src/ui/UserInfo.js b/vnext/src/ui/UserInfo.js index fe9cee19..00465252 100644 --- a/vnext/src/ui/UserInfo.js +++ b/vnext/src/ui/UserInfo.js @@ -1,7 +1,7 @@ import React, { useState, useEffect, useRef } from 'react'; import { Link } from 'react-router-dom'; -import { info, fetchUserUri } from '../api'; +import { info, fetchUserUri, update } from '../api'; import Avatar from './Avatar'; import Icon from './Icon'; @@ -13,29 +13,25 @@ let isMounted; /** * User info component - * @param {{user: string, onUpdate?: function, children?: Element}} props + * @param {{uname: string, onUpdate?: function, children?: React.ReactHTMLElement}} props */ -export default function UserInfo(props) { +export default function UserInfo({ uname, onUpdate, children }) { const [user, setUser] = useState({ - uname: props.user, + uname: uname, uid: 0 }); - const { onUpdate } = props; - const userRef = useRef(user); useEffect(() => { isMounted = true; - if (!userRef.current.avatar) { - info(userRef.current.uname).then(response => { - if (isMounted) { - onUpdate && onUpdate(response.data); - setUser(response.data); - } - }); - } + info(uname).then(response => { + if (isMounted) { + onUpdate && onUpdate(response.data); + setUser(response.data); + } + }); return () => { isMounted = false; }; - }, [onUpdate, props.user]); + }, [onUpdate, uname]); return ( <> <div className="userinfo"> @@ -63,7 +59,7 @@ export default function UserInfo(props) { </> } </div> - {props.children} + {children} </> ); } |