import { AvatarFallback, AvatarImage, color } from 'folds'; import React, { ReactEventHandler, ReactNode, useState } from 'react'; import classNames from 'classnames'; import * as css from './UserAvatar.css'; import colorMXID from '../../../util/colorMXID'; type UserAvatarProps = { className?: string; userId: string; src?: string; alt?: string; renderFallback: () => ReactNode; }; export function UserAvatar({ className, userId, src, alt, renderFallback }: UserAvatarProps) { const [error, setError] = useState(false); const handleLoad: ReactEventHandler = (evt) => { evt.currentTarget.setAttribute('data-image-loaded', 'true'); }; if (!src || error) { return ( {renderFallback()} ); } return ( setError(true)} onLoad={handleLoad} draggable={false} /> ); }