useVisible
Monitors an element and returns counts for how many times it has entered and exited the visible viewport area.
Importing
1
import { useVisible } from '@infinityfx/lively/hooks';Usage
Call signature
1
const [ref, entered, exited] = useVisible<T extends Element>(threshold?)
Parameters
threshold?:
number = 0.5The visibility threshold ratio required to register entry/exit events.
Returns
ref:
React.RefObject<T | null> A React ref to attach to the target DOM element.
entered:
number Total number of times the element entered the viewport.
exited:
number Total number of times the element exited the viewport.