I have installed Locomotive scroll and React Transition Group. but when I click on the link or open a page I can't scroll anymore and it will stick at the top of the screen.
I have added scroll.destory()
in my useEffect
but it doesn't work.
What should I do?
import { useEffect } from 'react';
import Head from 'next/head';
import { SwitchTransition, Transition } from 'react-transition-group';
import gsap from 'gsap';
import '@/styles/styles.scss';
export default function MyApp({ Component, pageProps, router }) {
function enter(node) {
gsap.from(node, {
duration: 0.5,
autoAlpha: 0,
});
}
function exit(node) {
gsap.to(node, {
duration: 0.5,
autoAlpha: 0,
});
}
useEffect(() => {
let scroll;
import('locomotive-scroll').then(
(locomotiveModule) => {
scroll = new locomotiveModule.default({
el: document.querySelector('[data-scroll-container]'),
smooth: true,
smoothMobile: false,
resetNativeScroll: true,
});
},
);
// `useEffect`'s cleanup phase
return () => scroll.destroy();
}, []);
return (
<>
<SwitchTransition>
<Transition
key={router.pathname}
timeout={100}
in={true}
onEnter={enter}
onExit={exit}
>
<main data-scroll-container className="container">
<Component {...pageProps} />
</main>
</Transition>
</SwitchTransition>
</>
);
}