reactopod
Version:
React Hooks for Typesaurus, type-safe Firestore ODM
24 lines (23 loc) • 760 B
JavaScript
Object.defineProperty(exports, '__esModule', { value: true })
const adaptor_1 = require('../adaptor')
function useInfiniteScroll(treshold, loadMore) {
adaptor_1.useEffect(() => {
const handleScroll = () => {
const scrollY = window.scrollY
const pageHeight = document.body.scrollHeight
const windowHeight = window.innerHeight
const leftHeight = pageHeight - scrollY - windowHeight
if (leftHeight < windowHeight * treshold) {
loadMore && loadMore()
}
}
handleScroll()
window.addEventListener('scroll', handleScroll)
return () => {
window.removeEventListener('scroll', handleScroll)
}
}, [loadMore])
}
exports.default = useInfiniteScroll
//# sourceMappingURL=index.js.map