Mitigate image flickering

This commit is contained in:
Sam Becker 2024-03-15 10:51:42 -05:00
parent e0f18171c0
commit 195569730f

View File

@ -4,7 +4,7 @@
import { BLUR_ENABLED } from '@/site/config';
import { clsx} from 'clsx/lite';
import Image, { ImageProps } from 'next/image';
import { useEffect, useRef, useState } from 'react';
import { useCallback, useEffect, useRef, useState } from 'react';
export default function ImageBlurFallback(props: ImageProps) {
const {
@ -18,6 +18,9 @@ export default function ImageBlurFallback(props: ImageProps) {
const [isLoading, setIsLoading] = useState(true);
const [didError, setDidError] = useState(false);
const onLoad = useCallback(() => setIsLoading(false), []);
const onError = useCallback(() => setDidError(true), []);
const [hideBlurPlaceholder, setHideBlurPlaceholder] = useState(false);
const imageClassName = 'object-cover h-full';
@ -80,8 +83,8 @@ export default function ImageBlurFallback(props: ImageProps) {
ref: imgRef,
priority,
className: imageClassName,
onLoad: () => setIsLoading(false),
onError: () => setDidError(true),
onLoad,
onError,
}} />
</div>
);