mirror of
https://github.com/reactjs/react.dev.git
synced 2026-02-23 20:23:08 +00:00
Simplify the observer example
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user