Created
March 12, 2022 16:05
-
-
Save amarbalu/8df5b6d75f081f520ff11b3b457e7c48 to your computer and use it in GitHub Desktop.
React loadable visibility -https://github.com/stratiformltd/react-loadable-visibility/blob/master/src/createLoadableVisibilityComponent.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let intersectionObserver; | |
const trackedElements = new Map(); | |
if (IntersectionObserver) { | |
intersectionObserver = new window.IntersectionObserver( | |
(entries, observer) => { | |
entries.forEach(entry => { | |
const visibilityHandler = trackedElements.get(entry.target); | |
if ( | |
visibilityHandler && | |
(entry.isIntersecting || entry.intersectionRatio > 0) | |
) { | |
visibilityHandler(); | |
} | |
}); | |
} | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment