import React, {useRef, useState} from 'react';
import multiavatar from '@multiavatar/multiavatar'

interface AvatarProps{
  src: string
  name: string
  alt?: string
}

export default function Avatar(props: AvatarProps) {
  const {
    src = '',
    alt = '',
    name=''
  } = props;

  const [error, setError] = useState(false);

  // 加载失败
  const onError = (obj: any) => {
    setError(true)
  };

  return <div dangerouslySetInnerHTML={{ __html: multiavatar(name) }} className="multiavatar-avatar"></div>
  // return error? <div dangerouslySetInnerHTML={{ __html: multiavatar(name) }} className="multiavatar-avatar"></div>: (
  //   <img
  //     src={src}
  //     alt={alt}
  //     onError={onError}
  //   />
  // );
}
