I got a list based on I render list items I want to track which elements overflows container (especially index of first elements that overflew) in order to do this I wanted to use react-intersection-observer library.
My problem:
const List = ({data}) => {
const { ref, inView, entry } = useInView({
threshold: 0,
root: ????
});
return (
<div>{data.map(i=><ListItem />)</div>
)
}
My solution which does not work.
const wrapperRef = useRef(null);
const { ref, inView, entry } = useInView({
threshold: 0,
root: wrapperRef
});
return (
<div ref={wrapperRef}>{data.map(i=><div ref={ref}><ListItem /></div>)</div>
)
Failed to construct 'IntersectionObserver': Failed to read the 'root' property from 'IntersectionObserverInit': The provided value is not of type '(Document or Element)'.
My question if my approach is correct and if yes how to set root?