Download src/lib/hooks/use-at-bottom.tsx from Specver/bingo: direct link, hf CLI and curl.
- Browser
- Download file 534 Bytes
-
https://huggingface.co/spaces/Specver/bingo/resolve/main/src/lib/hooks/use-at-bottom.tsx
- Command line
-
hf download hf://spaces/Specver/bingo/src/lib/hooks/use-at-bottom.tsx
-
curl -L -o use-at-bottom.tsx https://huggingface.co/spaces/Specver/bingo/resolve/main/src/lib/hooks/use-at-bottom.tsx
534 Bytes
| import * as React from 'react' | |
| export function useAtBottom(offset = 0) { | |
| const [isAtBottom, setIsAtBottom] = React.useState(false) | |
| React.useEffect(() => { | |
| const handleScroll = () => { | |
| setIsAtBottom( | |
| window.innerHeight + window.scrollY >= | |
| document.body.offsetHeight - offset | |
| ) | |
| } | |
| window.addEventListener('scroll', handleScroll, { passive: true }) | |
| handleScroll() | |
| return () => { | |
| window.removeEventListener('scroll', handleScroll) | |
| } | |
| }, [offset]) | |
| return isAtBottom | |
| } | |