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) 765 B
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],n):n((e||self).useOverflowScrollPosition={},e.react)}(this,function(e,n){e.useOverflowScrollPosition=function(e){var r=n.useState([null,null]),t=r[0],o=r[1],i=n.useCallback(function(){null!=e.current&&o([e.current.scrollTop+e.current.clientHeight,e.current.scrollHeight])},[e]);return n.useLayoutEffect(function(){if(null!=e.current)return i(),window.addEventListener("resize",i),e.current.addEventListener("scroll",i),function(){window.removeEventListener("resize",i),e.current&&e.current.removeEventListener("scroll",i)}},[e.current]),t}}); //# sourceMappingURL=use-overflow-scroll-position.umd.js.map