How to use @react-hook/window-scroll - 3 common examples

To help you get started, we’ve selected a few @react-hook/window-scroll examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jaredLunde / masonic / src / index.tsx View on Github external
export const useWindowScroller = (
  initialWidth: number,
  initialHeight: number,
  options: WindowScrollerOptions = emptyObj
): WindowScrollerResult => {
  const fps = options.scroll?.fps || 8
  const scrollY = useWindowScroll(fps)
  const [width, height] = useWindowSize(
    initialWidth,
    initialHeight,
    options.size || defaultSizeOpt
  )
  const [isScrolling, setIsScrolling] = useState(false)
  const isScrollingTimeout = useRef()

  useLayoutEffect(() => {
    if (isScrollingTimeout.current !== null) {
      clearTimeout(isScrollingTimeout.current)
      isScrollingTimeout.current = void 0
    }

    setIsScrolling(true)
    isScrollingTimeout.current = window.setTimeout(() => {
github jaredLunde / masonic / src / useWindowScroller.js View on Github external
export default (initialWidth, initialHeight, opt = emptyObj) => {
  const fps = opt.scroll?.fps || defaultScrollFps
  const scrollY = useWindowScroll(fps)
  const [width, height] = useWindowSize(
    initialWidth,
    initialHeight,
    opt.size || defaultSizeOpt
  )
  const [isScrolling, setIsScrolling] = useState(false)
  const isScrollingTimeout = useRef(null)

  useLayoutEffect(() => {
    if (isScrollingTimeout.current !== null) {
      clearTimeout(isScrollingTimeout.current)
      isScrollingTimeout.current = null
    }

    setIsScrolling(true)
    isScrollingTimeout.current = setTimeout(() => {
github codypearce / css-questions / src / ui / QuestionsHeader / QuestionsHeader.js View on Github external
const QuestionsHeader = ({ items, questions, isFixed, resetItems }) => {
  const scrollY = useWindowScroll(60);
  const scrollPoint = scrollY > 238;
  const fixedClass = isFixed && "question__header__fixed";
  const showFixed = isFixed && scrollPoint && "question__header__fixed--show";
  const hideNoneFixed = !isFixed && scrollPoint && "question__header--hide";

  return (
    <div>
      <span>
        {!items ? 0 : items.length}/{questions.length}
      </span>
      <button>
        Reset
      </button>
    </div>

@react-hook/window-scroll

A React hook for updating components when the scroll position of the window on the y-axis changes

MIT
Latest version published 5 years ago

Package Health Score

64 / 100
Full package analysis

Popular @react-hook/window-scroll functions