New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

react-use-scroll-progress

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-use-scroll-progress

Keep track of your element scroll progress.

latest
npmnpm
Version
0.2.0
Version published
Weekly downloads
295
298.65%
Maintainers
1
Weekly downloads
 
Created
Source

React Hook: Use Scroll Progress

Keep track of your element scroll progress.

Install

npm install --save react-use-scroll-progress

Getting Started

Make sure the element your tracking has height set and overflow-y set to 'scroll'. These two are required to receive scroll events which this hook is relaying on.

Use reference to track DOM scroll progress

import { useRef } from "react";
import { useScrollRef, getProgress } from "react-use-scroll-progress";

function MyComponent(props) {
  const ref = useRef(null);
  const state = useScrollRef(ref);

  console.log(state, getProgress(state));

  return (
    <div ref={ref} style={{ height: "300px", overflowY: "scroll" }}>
      Lorem p...
    </div>
  )
}

Use query selector to track DOM scroll progress

import { useEffect, useState } from "react";
import { useScrollElement, getProgress } from "react-use-scroll-progress";

function MyComponent(props) {
  const [dom, setDom] = useState<HTMLElement | null>(null);

  useEffect(() => {
    const node = document.querySelector("#feed") as HTMLElement | null;
    if (node) {
      setDom(node);
    }
  }, []);

  const state = useScrollElement(dom);
  console.log(state, getProgress(state));

  return (
    <div id="feed" style={{ height: "300px", overflowY: "scroll" }}>
      Lorem p...
    </div>
  )
}

FAQs

Package last updated on 02 Apr 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts