Keep track of your element scroll progress.
npm install react-use-scroll-progressKeep track of your element scroll progress.
``bash`
npm install --save react-use-scroll-progress
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.
`js
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 (
`
`js
import { useEffect, useState } from "react";
import { useScrollElement, getProgress } from "react-use-scroll-progress";
function MyComponent(props) {
const [dom, setDom] = useState
useEffect(() => {
const node = document.querySelector("#feed") as HTMLElement | null;
if (node) {
setDom(node);
}
}, []);
const state = useScrollElement(dom);
console.log(state, getProgress(state));
return (
``