import React 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'; export default class UserInfo extends React.Component { constructor(props) { super(props); this.state = { user: { uname: props.user, uid: 0 } }; } componentDidMount() { info(this.state.user.uname).then(response => { this.setState({ user: response.data }); this.props.onUpdate && this.props.onUpdate(response.data); }); } render() { const { user } = this.state; return ( <>
Was online recently
{ user.uid > 0 && <>
}
{this.props.children} ); } } UserInfo.propTypes = { user: PropTypes.string.isRequired, onUpdate: PropTypes.func, children: PropTypes.node };