Files
arjmand-pharmacy/components/Placeholder.tsx
T
Alireza HassaniandCursor 66e604c426 Connect the storefront to Meshkee catalog, blogs, and static image slots.
Wire homepage specials, product/blog pages, instant search, and the customer portal so the live pharmacy site can be managed from the dashboard.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-19 23:51:41 +03:30

35 lines
761 B
TypeScript

"use client";
import { useEffect, useRef, useState } from "react";
type PlaceholderProps = {
src: string;
fallbackSrc?: string;
alt?: string;
className?: string;
};
export function Placeholder({ src, fallbackSrc, alt = "", className }: PlaceholderProps) {
const [current, setCurrent] = useState(src);
const failed = useRef(false);
useEffect(() => {
failed.current = false;
setCurrent(src);
}, [src]);
return (
// eslint-disable-next-line @next/next/no-img-element
<img
src={current}
alt={alt}
className={className}
onError={() => {
if (failed.current || !fallbackSrc || fallbackSrc === current) return;
failed.current = true;
setCurrent(fallbackSrc);
}}
/>
);
}