Skip to content

Commit

Permalink
fallback image for 404 images
Browse files Browse the repository at this point in the history
  • Loading branch information
corwintines committed Nov 26, 2024
1 parent f112721 commit 23a5ab1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/components/EventCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ const EventCard: React.FC<EventCardProps> = ({
<img
src={imageUrl}
alt={title}
onError={(e) => {
e.currentTarget.onerror = null
e.currentTarget.src = EventFallback.src
}}
className="max-h-[224px] w-full object-cover xl:h-[124px]"
/>
) : (
Expand Down
14 changes: 13 additions & 1 deletion src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,15 @@ const HomePage = ({
>
<CardBanner>
{/* eslint-disable-next-line @next/next/no-img-element */}
<img src={imgSrc} alt="" loading="lazy" />
<img
src={imgSrc}
alt=""
loading="lazy"
onError={(e) => {
e.currentTarget.onerror = null
e.currentTarget.src = EventFallback.src
}}
/>
</CardBanner>
<CardContent>
<CardTitle>{title}</CardTitle>
Expand Down Expand Up @@ -808,6 +816,10 @@ const HomePage = ({
<img
src={imageUrl}
alt=""
onError={(e) => {
e.currentTarget.onerror = null
e.currentTarget.src = EventFallback.src
}}
className="max-w-full object-cover object-center"
loading="lazy"
/>
Expand Down

0 comments on commit 23a5ab1

Please sign in to comment.