infoalloggi-monorepo/apps/infoalloggi/src/components/ImageWithFallback.tsx

20 lines
424 B
TypeScript
Raw Normal View History

2025-08-04 17:45:44 +02:00
import Image from "next/image";
2025-08-28 18:27:07 +02:00
import type { ComponentProps } from "react";
2025-08-04 17:45:44 +02:00
const fallbackImage = "/fallback-image.png";
export const ImageFlbk = (props: ComponentProps<typeof Image>) => {
2025-08-28 18:27:07 +02:00
return (
<Image
{...props}
onLoad={(e) => {
if (e.currentTarget.naturalWidth === 0) {
e.currentTarget.src = fallbackImage;
}
}}
onError={(e) => {
e.currentTarget.src = fallbackImage;
}}
/>
);
2025-08-04 17:45:44 +02:00
};