Browse Source

Simplify the observer example

main
Dan Abramov 6 years ago
committed by GitHub
parent
commit
ad6687e25e
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      content/docs/hooks-faq.md

9
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()

Loading…
Cancel
Save