infoalloggi-monorepo/apps/infoalloggi/src/components/ImageWithFallback.tsx
2025-08-29 16:18:32 +02:00

19 lines
424 B
TypeScript

import Image from "next/image";
import type { ComponentProps } from "react";
const fallbackImage = "/fallback-image.png";
export const ImageFlbk = (props: ComponentProps<typeof Image>) => {
return (
<Image
{...props}
onError={(e) => {
e.currentTarget.src = fallbackImage;
}}
onLoad={(e) => {
if (e.currentTarget.naturalWidth === 0) {
e.currentTarget.src = fallbackImage;
}
}}
/>
);
};