commerce/components/page/image-display.tsx
Chloe 0471e07633
fix: optimize image loading on homepage
Signed-off-by: Chloe <pinkcloudvnn@gmail.com>
2024-06-11 20:28:07 +07:00

30 lines
680 B
TypeScript

import { getImage } from 'lib/shopify';
import Image from 'next/image';
import { twMerge } from 'tailwind-merge';
const ImageDisplay = async ({
fileId,
title,
className,
...props
}: {
fileId?: string;
title: string;
className?: string;
} & Omit<React.ComponentProps<typeof Image>, 'src' | 'alt'>) => {
if (!fileId) return null;
const image = await getImage(fileId);
return (
<Image
src={image.url}
alt={image.altText || `Display Image for ${title} section`}
width={image.width}
height={image.height}
className={twMerge('h-full w-full object-contain', className)}
{...props}
/>
);
};
export default ImageDisplay;