UNPKG

@unlazy/react

Version:

React lazy loading library for placeholder images

36 lines (35 loc) 1.71 kB
import type { ImgHTMLAttributes } from 'react'; import type { UnLazyLoadOptions } from 'unlazy'; interface Props extends ImgHTMLAttributes<HTMLImageElement>, Pick<UnLazyLoadOptions, 'placeholderSize'> { /** Image source URL to be lazy-loaded. */ src?: ImgHTMLAttributes<HTMLImageElement>['src']; /** Image source set to be lazy-loaded. */ srcSet?: ImgHTMLAttributes<HTMLImageElement>['srcSet']; /** * A flag to indicate whether the sizes attribute should be automatically calculated. * @default false */ autoSizes?: boolean; /** A BlurHash string representing the blurry placeholder image. */ blurhash?: string; /** A ThumbHash string representing the blurry placeholder image. */ thumbhash?: string; /** Optional image source URL for a custom placeholder image. Will be ignored if a BlurHash or ThumbHash is provided. */ placeholderSrc?: string; /** * A flag to indicate whether the image should be preloaded, even if it is not in the viewport yet. * @default false */ preload?: boolean; /** * Allows to specify the loading strategy of the image. * @default 'lazy' */ loading?: ImgHTMLAttributes<HTMLImageElement>['loading']; /** A callback function to run when the image is loaded. */ onImageLoad?: (image: HTMLImageElement) => void; /** A callback function to run when the image fails to load. */ onImageError?: (image: HTMLImageElement, error: Event) => void; } export declare function UnLazyImage({ src, srcSet, autoSizes, blurhash, thumbhash, placeholderSrc, placeholderSize, preload, loading, onImageLoad, onImageError, ...rest }: Props): import("react").JSX.Element; export {};