import React, {useState} from "react";
import {UserUrl} from "../core/api";


interface IUser {
    name?: string;
    avatarUrl?: string;
}

export default function User() {

    const [user, setUser] = useState<IUser>({
        name: "---",
        avatarUrl: ""
    });


    fetch(UserUrl)
        .then(res => res.json())
        .then(
            (data) => {
                console.log(data);
                setUser({name: data.name, avatarUrl: data.avatarUrl});
            },
            (error) => {
                console.log("error");
            }
        );

     return (
     <span>
         Welcome {user.name} -
         <span> </span><img width="50" height="50" src={user.avatarUrl}/>
     </span>
    )

}

