Skip to content

Commit 0a67de9

Browse files
perf(react): simplify effect
1 parent c04ee0f commit 0a67de9

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

packages/react/src/index.tsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,17 @@ export function UnLazyImage({
3636
const target = useRef<HTMLImageElement | null>(null)
3737

3838
useEffect(() => {
39-
if (target.current) {
40-
const cleanup = lazyLoad(target.current, {
41-
hash: thumbhash || blurhash,
42-
hashType: thumbhash ? 'thumbhash' : 'blurhash',
43-
placeholderSize,
44-
})
45-
return () => {
46-
cleanup()
47-
}
39+
if (!target.current)
40+
return
41+
42+
const cleanup = lazyLoad(target.current, {
43+
hash: thumbhash || blurhash,
44+
hashType: thumbhash ? 'thumbhash' : 'blurhash',
45+
placeholderSize,
46+
})
47+
48+
return () => {
49+
cleanup()
4850
}
4951
}, [src, srcSet, autoSizes, blurhash, thumbhash, placeholderSrc, placeholderSize])
5052

0 commit comments

Comments
 (0)