Download react-spring/docs/app/hooks/useStickyHeader.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 737 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-spring/docs/app/hooks/useStickyHeader.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-spring/docs/app/hooks/useStickyHeader.ts
-
curl -L -o useStickyHeader.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-spring/docs/app/hooks/useStickyHeader.ts
737 Bytes
| import { useState } from 'react' | |
| import { useIsomorphicLayoutEffect } from './useIsomorphicEffect' | |
| import { useWindowScrolling } from './useWindowScrolling' | |
| export const useStickyHeader = (heights: [desktop: number, mobile: number]) => { | |
| const [stickyHeader, setStickyHeader] = useState(false) | |
| const [direction, scrollTop] = useWindowScrolling({ | |
| active: true, | |
| }) | |
| useIsomorphicLayoutEffect(() => { | |
| const { innerWidth } = window | |
| const limit = innerWidth < 768 ? heights[1] : heights[0] | |
| if (scrollTop >= limit && direction === 'down') { | |
| setStickyHeader(true) | |
| } else if (direction === 'up' && scrollTop === 0) { | |
| setStickyHeader(false) | |
| } | |
| }, [scrollTop, direction]) | |
| return stickyHeader | |
| } | |