File tree Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,8 @@ const LazyLoadComponent = <T extends React.ElementType>({
17
17
const ref = useRef < HTMLDivElement > ( null )
18
18
19
19
useEffect ( ( ) => {
20
+ const obsRef = ref . current
21
+
20
22
const observer = new IntersectionObserver ( ( [ entry ] ) => {
21
23
// Update the state when observer callback fires
22
24
if ( entry . isIntersecting ) {
@@ -25,17 +27,17 @@ const LazyLoadComponent = <T extends React.ElementType>({
25
27
}
26
28
} , intersectionOptions )
27
29
28
- if ( ref . current ) {
29
- observer . observe ( ref . current )
30
+ if ( obsRef ) {
31
+ observer . observe ( obsRef )
30
32
}
31
33
32
34
// Clean up the observer on component unmount
33
35
return ( ) => {
34
- if ( ref . current ) {
36
+ if ( obsRef ) {
35
37
observer . disconnect ( )
36
38
}
37
39
}
38
- } , [ ] )
40
+ } , [ intersectionOptions ] )
39
41
40
42
return (
41
43
< div ref = { ref } >
You can’t perform that action at this time.
0 commit comments