UNPKG

@byteclaw/use-overflow-scroll-position

Version:

React hook for calculating number of pixels scrolled through in an overflow:scroll enabled container

3 lines (2 loc) 575 B
import{useState as r,useCallback as e,useLayoutEffect as n}from"react";function t(t){var c=r([null,null]),u=c[0],i=c[1],l=e(function(){null!=t.current&&i([t.current.scrollTop+t.current.clientHeight,t.current.scrollHeight])},[t]);return n(function(){if(null!=t.current)return l(),window.addEventListener("resize",l),t.current.addEventListener("scroll",l),function(){window.removeEventListener("resize",l),t.current&&t.current.removeEventListener("scroll",l)}},[t.current]),u}export{t as useOverflowScrollPosition}; //# sourceMappingURL=use-overflow-scroll-position.esm.js.map