import React, { useState, useEffect } from 'react'; import PropTypes from 'prop-types'; import { Link } from 'react-router-dom'; import { UserType } from './Types'; import { info } from '../api'; import Avatar from './Avatar'; import Icon from './Icon'; 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 => { if (isMounted) { setUser(response.data); props.onUpdate && props.onUpdate(response.data); } }); return () => { isMounted = false; }; }, []); return ( <>