UNPKG

@xo-union/tk-component-header-nav

Version:
22 lines 759 B
import _setTimeout from "@babel/runtime-corejs3/core-js/set-timeout"; import _globalThis from "@babel/runtime-corejs3/core-js/global-this"; import React from "react"; const useAnimationEnabled = () => { const resetTimer = React.useRef(); const [animationEnabled, setAnimationEnabled] = React.useState(true); React.useEffect(() => { const onResize = () => { clearTimeout(resetTimer.current); setAnimationEnabled(false); resetTimer.current = _setTimeout(() => { setAnimationEnabled(true); }, 300); }; _globalThis.addEventListener('resize', onResize); return () => { _globalThis.removeEventListener('resize', onResize); }; }, []); return animationEnabled; }; export default useAnimationEnabled;