Zum Hauptinhalt springen
Echtzeit-Radar & Feeds
Alle RSS Feeds ➔
👥 Community & Social
Linux Tipps & HardeningSecurity: Ausführen beliebiger Kommandos in perl-Dancer2 (Fedora)(29.09.2026 um 07:43 Uhr)
•
Linux Tipps & HardeningSecurity: Denial of Service in perl-HTML-FormFu (Fedora)(29.09.2026 um 07:46 Uhr)
••
Linux Tipps & HardeningSecurity: Zwei Probleme in NetworkManager-l2tp (Fedora)(29.09.2026 um 07:46 Uhr)
••
Sicherheitslücken (CVE)CVE-2026-77144 | TYPO3 Events 2 Plugin up to 10.2.11 permission(29.09.2026 um 06:21 Uhr)
•
Sicherheitslücken (CVE)CVE-2026-21753 | HCL Hive 1.0 unmaintained third party components(29.09.2026 um 06:21 Uhr)
••
Sicherheitslücken (CVE)CVE-2026-75038 | ilya-zlobintsev LACT up to 0.10.0 symlink(29.09.2026 um 06:21 Uhr)
••
Linux Tipps & HardeningSecurity: Ausführen beliebiger Kommandos in perl-Dancer2 (Fedora)(29.09.2026 um 07:43 Uhr)
•
Linux Tipps & HardeningSecurity: Denial of Service in perl-HTML-FormFu (Fedora)(29.09.2026 um 07:46 Uhr)
••
Linux Tipps & HardeningSecurity: Zwei Probleme in NetworkManager-l2tp (Fedora)(29.09.2026 um 07:46 Uhr)
••
Sicherheitslücken (CVE)CVE-2026-77144 | TYPO3 Events 2 Plugin up to 10.2.11 permission(29.09.2026 um 06:21 Uhr)
•
Sicherheitslücken (CVE)CVE-2026-21753 | HCL Hive 1.0 unmaintained third party components(29.09.2026 um 06:21 Uhr)
••
Sicherheitslücken (CVE)CVE-2026-75038 | ilya-zlobintsev LACT up to 0.10.0 symlink(29.09.2026 um 06:21 Uhr)
••
Intelligence View
⚡ tsecurity.de Intelligence

Beautifying the HTMLImageElement not-loaded/errored status display, react component

background Browser's native image not loaded status doesn't look good, I'd like not to use it. I am using react. ideas Determine if the image is loaded successfully by onLoaded event. If loaded successfully show the…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!




background




  • Browser's native image not loaded status doesn't look good, I'd like not to use it.

  • I am using react.






ideas




  • Determine if the image is loaded successfully by onLoaded event.

  • If loaded successfully show the HTMLImageElement, if not show the custom error component while HTMLImageElement is hidden (visibility: hidden).






how it looks like






fail



Image description






fail with alt on it



Image description






success



Image description






tips




  • When load failed, the HTMLImageElement can't be set to display: none, the HTMLImageElement needs to be in the document tree. Also the HTMLImageElement should to be invisible and looks like not placed in the web page, so use the grid display to implement this.


  • every time the image is changed, will reload again, so need to set loaded status to false first.







reference








import { cn } from "@/lib/utils";
import { Image } from "lucide-react";
import { useEffect, useState } from "react";
interface ImageProps {
src: string;
iconSize?: number;
className?: string;
alt?: string;
showAlt?: boolean;
}

const BeautyImage = ({
src,
iconSize = 16,
className = "",
alt = "",
showAlt = false,
}: ImageProps) => {
// load successfully or not
const [imageLoaded, setImageLoaded] = useState(false);

/**
* onLoad event
*/
const onImageLoad = () => {
setImageLoaded(true);
};

/**
* everytime the src changes, set load status to fail
*/
useEffect(() => {
setImageLoaded(false);
}, [src]);

return (
<div
className={cn(
"flex flex-col justify-center items-center text-xs text-ttertiary",
className
)}
>
<div
className={cn(
"grid",
imageLoaded
? "grid-rows-[1fr] opacity-100"
: "grid-rows-[0fr] opacity-0"
)}
>
<div className="overflow-hidden">
<img className="rounded-full" src={src} onLoad={onImageLoad} />
</div>
</div>
{/* custom error component */}
{!imageLoaded && (
<div className="flex flex-col items-center justify-center">
<Image size={iconSize} />
{showAlt && alt && <p>{alt}</p>}
</div>
)}
</div>
);
};


Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Beautifying the HTMLImageElement not-loaded/errored status display, react component

Thematisch verwandte Begriffe: Beautifying, HTMLImageElement, notloadederrored, status · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

💬 Kommentare werden geladen…
Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-102367 | mall4j through 4.0 contains an insufficient session expiration vulnerab…
Advisory →
tsecurity.de Icon
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag