rehooks/ideas

visibility sensor for an element in a page

imbhargav5 opened this issue · 4 comments

Check if an element is scrolled into view.

import {useRef} from "react"
import useVisibilitySensor from '@rehooks/visibility-sensor';

const StyledDiv = styled.div`
  opacity : ${props=>props.isVisible? 1 : 0.2}; 
`
function MyComponent() {
  const elementToObserve = useRef(null);
  let visibility = useVisibilitySensor(elementToObserve);
  return <StyledDiv ref={elementToObserve} {...visibility} />;
}

I want to claim this if it's possible.

Started work on it.

Almost done.

@jamiebuilds What do you think?