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) 551 B
import{useState as r,useCallback as e,useLayoutEffect as n}from"react";function t(t){const[c,l]=r([null,null]),u=e(()=>{null!=t.current&&l([t.current.scrollTop+t.current.clientHeight,t.current.scrollHeight])},[t]);return n(()=>{if(null!=t.current)return u(),window.addEventListener("resize",u),t.current.addEventListener("scroll",u),()=>{window.removeEventListener("resize",u),t.current&&t.current.removeEventListener("scroll",u)}},[t.current]),c}export{t as useOverflowScrollPosition}; //# sourceMappingURL=use-overflow-scroll-position.modern.js.map