import React from 'react'; import PropTypes from 'prop-types'; import { Link } from 'react-router-dom'; import { UserType } from './Types'; import Icon from './Icon'; import { fetchUserUri } from '../api'; import './Avatar.css'; class Avatar extends React.Component { constructor(props) { super(props); this.state = { user: props.user }; } componentDidMount() { let user = this.state.user; if (!user.uid && user.uri) { fetchUserUri(user.uri).then(response => { this.setState({ user: response.data }); }); } } render() { let user = this.state.user; return (
{ user.uname ? {user.avatar ? {`${user.uname}`} : } : }
{user.uname} {this.props.children}
); } } export default Avatar; export const AvatarLink = React.memo(props => { return ( {`${props.user.uname}`} {props.user.uname} ); }); Avatar.propTypes = { user: UserType, link: PropTypes.string, style: PropTypes.object, children: PropTypes.node };