Download wp-calypso/client/my-sites/plugins/plugins-browser/use-is-visible.tsx from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 674 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/my-sites/plugins/plugins-browser/use-is-visible.tsx
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/client/my-sites/plugins/plugins-browser/use-is-visible.tsx
-
curl -L -o use-is-visible.tsx https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/my-sites/plugins/plugins-browser/use-is-visible.tsx
674 Bytes
| import { RefObject, useEffect, useMemo, useState } from 'react'; | |
| export default function useIsVisible( | |
| ref: RefObject< HTMLElement >, | |
| options?: IntersectionObserverInit | |
| ) { | |
| const [ isIntersecting, setIntersecting ] = useState< boolean | undefined >( undefined ); | |
| const observer = useMemo( () => { | |
| if ( typeof window === 'undefined' ) { | |
| return; | |
| } | |
| return new IntersectionObserver( | |
| ( [ entry ] ) => setIntersecting( entry.isIntersecting ), | |
| options | |
| ); | |
| }, [ options ] ); | |
| useEffect( () => { | |
| if ( ref && ref.current ) { | |
| observer?.observe( ref.current ); | |
| } | |
| return () => observer?.disconnect(); | |
| }, [ observer, ref ] ); | |
| return isIntersecting; | |
| } | |