Dan Abramov
6 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with
3 additions and
6 deletions
-
content/docs/hooks-faq.md
|
|
@ -809,13 +809,10 @@ function Image(props) { |
|
|
|
|
|
|
|
// ✅ IntersectionObserver is created lazily once |
|
|
|
function getObserver() { |
|
|
|
let observer = ref.current; |
|
|
|
if (observer !== null) { |
|
|
|
return observer; |
|
|
|
if (ref.current === null) { |
|
|
|
ref.current = new IntersectionObserver(onIntersect); |
|
|
|
} |
|
|
|
let newObserver = new IntersectionObserver(onIntersect); |
|
|
|
ref.current = newObserver; |
|
|
|
return newObserver; |
|
|
|
return ref.current; |
|
|
|
} |
|
|
|
|
|
|
|
// When you need it, call getObserver() |
|
|
|