Skip to content

Commit 0db834b

Browse files
authored
Merge pull request #13466 from ethereum/fix-lazyload-ref-warning
Fix `ref` warning
2 parents 62238f3 + dc210ce commit 0db834b

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/components/LazyLoadComponent.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ const LazyLoadComponent = <T extends React.ElementType>({
1717
const ref = useRef<HTMLDivElement>(null)
1818

1919
useEffect(() => {
20+
const obsRef = ref.current
21+
2022
const observer = new IntersectionObserver(([entry]) => {
2123
// Update the state when observer callback fires
2224
if (entry.isIntersecting) {
@@ -25,17 +27,17 @@ const LazyLoadComponent = <T extends React.ElementType>({
2527
}
2628
}, intersectionOptions)
2729

28-
if (ref.current) {
29-
observer.observe(ref.current)
30+
if (obsRef) {
31+
observer.observe(obsRef)
3032
}
3133

3234
// Clean up the observer on component unmount
3335
return () => {
34-
if (ref.current) {
36+
if (obsRef) {
3537
observer.disconnect()
3638
}
3739
}
38-
}, [])
40+
}, [intersectionOptions])
3941

4042
return (
4143
<div ref={ref}>

0 commit comments

Comments
 (0)