Skip to content

Commit ef4fc8e

Browse files
authored
fix: fixed logo refetch on re-render (#2978)
1 parent 3dc144c commit ef4fc8e

File tree

1 file changed

+5
-2
lines changed
  • apps/kyb-app/src/components/layouts/AppShell

1 file changed

+5
-2
lines changed

apps/kyb-app/src/components/layouts/AppShell/Logo.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { useRefValue } from '@/hooks/useRefValue';
12
import { useEffect } from 'react';
23

34
interface Props {
@@ -16,14 +17,16 @@ const prefetchImage = (url: string) =>
1617
const fallback = (timeout: number) => new Promise(resolve => setTimeout(resolve, timeout));
1718

1819
export const Logo = ({ logoSrc, appName, onLoad }: Props) => {
20+
const onLoadRef = useRefValue(onLoad);
21+
1922
useEffect(() => {
2023
if (!onLoad) {
2124
return;
2225
}
2326

2427
// Using race here in case if image is corrupted or load takes to long we don't want to lock stepper breadcrumbs forever.
25-
Promise.race([prefetchImage(logoSrc), fallback(3000)]).then(onLoad);
26-
}, [logoSrc, onLoad]);
28+
Promise.race([prefetchImage(logoSrc), fallback(3000)]).then(onLoadRef.current);
29+
}, [logoSrc, onLoadRef]);
2730

2831
return <img src={logoSrc} alt={appName} className="max-h-[80px] max-w-[200px] object-cover" />;
2932
};

0 commit comments

Comments
 (0)