Now’s the time! Finally, we are ready to implement the Infinite Scroll.
We want to load more content as users scroll down. Here, we can use loadMoreButton as a landmark. When loadMoreButton appears in view, we click it, so it loads the next set of content.
const observer = new IntersectionObserver(entries => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.click()
}
})
})
observer.observe(loadMoreButton)