We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
import { useRef, useState, useEffect, RefObject } from 'react' import 'intersection-observer' type UseVisibilityType = ( node: RefObject<any>, options?: IntersectionObserverInit | undefined ) => IntersectionObserverEntry | object const useVisibility: UseVisibilityType = (node, options = {}) => { const [visible, setVisibilty] = useState({}) const isIntersecting = useRef({}) const handleObserverUpdate: IntersectionObserverCallback = entries => { const ent = entries[0] if (isIntersecting.current !== ent.isIntersecting) { setVisibilty(ent) isIntersecting.current = ent.isIntersecting } } const observer = new IntersectionObserver(handleObserverUpdate, options) useEffect(() => { const element = node.current if (!element) { return } observer.observe(element) return function cleanup() { observer.unobserve(element) } }) return visible } export { useVisibility }
The text was updated successfully, but these errors were encountered:
Once I am done with my current branch I'll share my tests
Sorry, something went wrong.
@artokun feel free to open a PR if you feel like.
No branches or pull requests
The text was updated successfully, but these errors were encountered: