diff options
| author | trisusilo48 <tri.susilo@altama.co.id> | 2024-07-10 15:58:51 +0700 |
|---|---|---|
| committer | trisusilo48 <tri.susilo@altama.co.id> | 2024-07-10 15:58:51 +0700 |
| commit | 2e3c726bc8217f3960cfecec44b81303b03de72b (patch) | |
| tree | 1b85ced7f61f3e4c3f1f27b577b37aa161615065 /src/core/components/ScrollToTop.jsx | |
| parent | 2b3bd9c0a454dbad69ce29cee877bfb1fca5dfa6 (diff) | |
| parent | a99bf6480eea556e53b85e6db45f3b8c2361e693 (diff) | |
Merge branch 'release' into development
# Conflicts:
# src/pages/shop/product/variant/[slug].jsx
Diffstat (limited to 'src/core/components/ScrollToTop.jsx')
| -rw-r--r-- | src/core/components/ScrollToTop.jsx | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/core/components/ScrollToTop.jsx b/src/core/components/ScrollToTop.jsx new file mode 100644 index 00000000..f8e85167 --- /dev/null +++ b/src/core/components/ScrollToTop.jsx @@ -0,0 +1,24 @@ +import { useEffect } from 'react'; +import { useRouter } from 'next/router'; + +const ScrollToTop = () => { + const router = useRouter(); + + useEffect(() => { + const handleRouteChange = (url, { shallow }) => { + if (!shallow) { + window.scrollTo(0, 0); + } + }; + + router.events.on('routeChangeComplete', handleRouteChange); + + return () => { + router.events.off('routeChangeComplete', handleRouteChange); + }; + }, [router.events]); + + return null; +}; + +export default ScrollToTop; |
