From 54ce032ba173a656bd68c1493aa05d7a4da723cb Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 6 Feb 2019 23:47:04 +0300 Subject: UserInfo: do not update state when unmounted --- vnext/src/components/UserInfo.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'vnext/src') diff --git a/vnext/src/components/UserInfo.js b/vnext/src/components/UserInfo.js index d772d76e..b08355f8 100644 --- a/vnext/src/components/UserInfo.js +++ b/vnext/src/components/UserInfo.js @@ -12,13 +12,21 @@ import SearchBox from './SearchBox'; import './UserInfo.css'; +let isMounted; + export default function UserInfo(props) { const [user, setUser] = useState({ uname: props.user, uid: 0 }); useEffect(() => { + isMounted = true; info(user.uname).then(response => { - setUser(response.data); - props.onUpdate && props.onUpdate(response.data); + if (isMounted) { + setUser(response.data); + props.onUpdate && props.onUpdate(response.data); + } }); + return () => { + isMounted = false; + }; }); return ( <> -- cgit v1.2.3