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'; export default function UserInfo(props) { const [user, setUser] = useState({ uname: props.user, uid: 0 }); useEffect(() => { info(user.uname).then(response => { setUser(response.data); props.onUpdate && props.onUpdate(response.data); }); }); return ( <>
Was online recently
{ user.uid > 0 && <> PM Recommendations Photos { user.read && I read: {user.read.length} } My readers: {user.readers ? user.readers.length : 0} { user.statsMyBL && My blacklist: {user.statsMyBL} } }
{props.children} ); } UserInfo.propTypes = { user: PropTypes.string.isRequired, onUpdate: PropTypes.func, children: PropTypes.node };