From 5d4ff506a0d1ebebe92900985b7bce74501b658d Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Mon, 25 Feb 2019 15:38:10 +0300 Subject: Fix Avatar state update - https://stackoverflow.com/questions/54865764 --- vnext/src/components/Avatar.js | 3 ++- vnext/src/components/Types.js | 3 ++- vnext/src/components/UserInfo.js | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) (limited to 'vnext/src') diff --git a/vnext/src/components/Avatar.js b/vnext/src/components/Avatar.js index 67d75c5e..64c16ead 100644 --- a/vnext/src/components/Avatar.js +++ b/vnext/src/components/Avatar.js @@ -15,6 +15,7 @@ let isMounted; function Avatar(props) { const [user, setUser] = useState(props.user); useEffect(() => { + setUser(props.user); isMounted = true; if (!user.uid && user.uri) { fetchUserUri(user.uri).then(response => { @@ -26,7 +27,7 @@ function Avatar(props) { isMounted = false; }; } - }); + }, [props.user]); return (
diff --git a/vnext/src/components/Types.js b/vnext/src/components/Types.js index db90d41e..5a495ff3 100644 --- a/vnext/src/components/Types.js +++ b/vnext/src/components/Types.js @@ -2,7 +2,8 @@ import PropTypes from 'prop-types'; export const UserType = PropTypes.shape({ uid: PropTypes.number, - uname: PropTypes.string + uname: PropTypes.string, + avatar: PropTypes.string }); export const MessageType = PropTypes.shape({ diff --git a/vnext/src/components/UserInfo.js b/vnext/src/components/UserInfo.js index b08355f8..c76ef0c7 100644 --- a/vnext/src/components/UserInfo.js +++ b/vnext/src/components/UserInfo.js @@ -27,7 +27,7 @@ export default function UserInfo(props) { return () => { isMounted = false; }; - }); + }, []); return ( <>
-- cgit v1.2.3