Skip to content
Advertisement

How to correctly use Locomotive Scroll with Next.js routing?

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:

JavaScript

Advertisement

Answer

You should move the scroll.destroy call to the cleanup phase of the useEffect. You also don’t need to explicitly call scroll.init().

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement