import React, { useState } from 'react' import { ImageProps } from './images.types' import { WraaperImage } from './image.style' import { Skeleton } from '../skeleton' import { ImageError } from './ImageError' export const Image: React.FC = ({ src, loading, alt, loadingType, width, height, styles, style, spinnerColor, ...restprops }) => { const [isLoading, setIsloading] = useState(true) const [isError, setIsError] = useState(false) const LoadImage = () => setIsloading((prev) => false) const ErrorImage = () => setIsError(true) return ( {loadingType === 'spinner' && ( <> {isError ? false : isLoading &&
} {!isError ? ( {alt} { ErrorImage() }} /> ) : ( )} )} {loadingType === 'skeleton' && ( {!isError ? ( {alt} { ErrorImage() }} /> ) : ( )} )}
) }