mirror of
https://github.com/jakejarvis/hoot.git
synced 2025-10-18 20:14:25 -04:00
Refactor Favicon component to remove unused loading state and simplify image loading logic
This commit is contained in:
@@ -20,7 +20,6 @@ export function Favicon({
|
||||
const trpc = useTRPC();
|
||||
const [isHydrated, setIsHydrated] = useState(false);
|
||||
const [failedUrl, setFailedUrl] = useState<string | null>(null);
|
||||
const [isLoaded, setIsLoaded] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
setIsHydrated(true);
|
||||
@@ -39,12 +38,6 @@ export function Favicon({
|
||||
|
||||
const url = data?.url ?? null;
|
||||
|
||||
// Reset the fade-in state when the image URL changes to animate again
|
||||
// biome-ignore lint/correctness/useExhaustiveDependencies: this is intentional.
|
||||
useEffect(() => {
|
||||
setIsLoaded(false);
|
||||
}, [url]);
|
||||
|
||||
if (!isHydrated || isPending) {
|
||||
return (
|
||||
<Skeleton
|
||||
@@ -71,15 +64,10 @@ export function Favicon({
|
||||
alt={`${domain} icon`}
|
||||
width={size}
|
||||
height={size}
|
||||
className={cn(
|
||||
className,
|
||||
"transition-opacity duration-200",
|
||||
isLoaded ? "opacity-100" : "opacity-0",
|
||||
)}
|
||||
className={className}
|
||||
loading="lazy"
|
||||
unoptimized
|
||||
onError={() => setFailedUrl(url)}
|
||||
onLoad={() => setIsLoaded(true)}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user