Skip to content

Commit f3de678

Browse files
committed
fix(use-image): set status after hydrated
1 parent 0eb96f6 commit f3de678

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

.changeset/fair-pigs-tap.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@nextui-org/use-image": patch
3+
---
4+
5+
set status after hydrated

packages/hooks/use-image/src/index.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,7 @@ export function useImage(props: UseImageProps = {}) {
7171

7272
const imageRef = useRef<HTMLImageElement | null>(isHydrated ? new Image() : null);
7373

74-
const [status, setStatus] = useState<Status>(() =>
75-
isHydrated ? setImageAndGetInitialStatus(props, imageRef) : "pending",
76-
);
74+
const [status, setStatus] = useState<Status>("pending");
7775

7876
useEffect(() => {
7977
if (!imageRef.current) return;
@@ -97,6 +95,12 @@ export function useImage(props: UseImageProps = {}) {
9795
}
9896
};
9997

98+
useEffect(() => {
99+
if (isHydrated) {
100+
setStatus(setImageAndGetInitialStatus(props, imageRef));
101+
}
102+
}, [isHydrated]);
103+
100104
/**
101105
* If user opts out of the fallback/placeholder
102106
* logic, let's just return 'loaded'

0 commit comments

Comments
 (0)