mirror of
https://github.com/plausible/analytics.git
synced 2024-12-22 09:01:40 +03:00
23 lines
519 B
JavaScript
23 lines
519 B
JavaScript
import React, { useEffect, useState } from 'react'
|
|
import { useInView } from 'react-intersection-observer'
|
|
|
|
export default function LazyLoader(props) {
|
|
const [hasBecomeVisibleYet, setHasBecomeVisibleYet] = useState(false)
|
|
const { ref, inView } = useInView({
|
|
threshold: 0,
|
|
})
|
|
|
|
useEffect(() => {
|
|
if (inView && !hasBecomeVisibleYet) {
|
|
setHasBecomeVisibleYet(true)
|
|
props.onVisible && props.onVisible()
|
|
}
|
|
}, [inView])
|
|
|
|
return (
|
|
<div ref={ref}>
|
|
{props.children}
|
|
</div>
|
|
)
|
|
}
|