I'm using locomotive-scroll
with Next.js and all working fine. But after route to a different page, my scroll won't destroy and 2 scrolls overlap each other.
How to correctly reinit locomotive-scroll
in Next.js after route?
My code example:
function MyApp({ Component, pageProps }) {
useEffect(() => {
import("locomotive-scroll").then((locomotiveModule) => {
let scroll = new locomotiveModule.default({
el: document.querySelector("[data-scroll-container]"),
smooth: true,
smoothMobile: false,
resetNativeScroll: true,
});
scroll.destroy(); //<-- DOESN'T WORK OR IDK
setTimeout(function () {
scroll.init();
}, 400);
});
});
return (
<main data-scroll-container>
<Component {...pageProps} />
</main>
);
}