useScroll

React hook for detecting when the user scrolls past a certain threshold.

Installation

npm install @mvdlei/hooks

Example

Usage

import React from "react";
import { useScroll } from "@mvdlei/hooks";
 
const MyComponent = () => {
  const hasScrolledPastThreshold = useScroll(200);
 
  return (
    <div>
      <p>
        {hasScrolledPastThreshold
          ? "Scrolled Past Threshold"
          : "Not Scrolled Past Threshold"}
      </p>
    </div>
  );
};

Reference

useScroll(threshold: number): boolean;

Parameters

  • threshold: The threshold to be scrolled past.

Return Value

A boolean indicating whether the user has scrolled past the specified threshold or not.

use-scroll.ts