@guruhotel/aura-hooks
Version:
🪝 Hooks library designed by the Guruhotel team for Aura UI
1 lines • 522 B
JavaScript
import{useState as o,useEffect as e}from"react";import{useWindowEvent as n}from"../use-window-event/use-window-event";function t(){return"undefined"!=typeof window?{x:window.pageXOffset,y:window.pageYOffset}:{x:0,y:0}}function i({x:o,y:e}){if("undefined"!=typeof window){const n={behavior:"smooth"};"number"==typeof o&&(n.left=o),"number"==typeof e&&(n.top=e),window.scrollTo(n)}}export function useWindowScroll(){const[f,r]=o({x:0,y:0});return n("scroll",(()=>r(t()))),n("resize",(()=>r(t()))),e((()=>{r(t())}),[]),[f,i]}