locomotive-scroll
locomotive-scroll copied to clipboard
Locomotive scroll with typescript
I'm using gatsby typescript to create a project. When I run local development it's fine, but when I run build genarate it's an error. That's because i use locomotive scroll using document object.
I'm always frustrated when looking for such problems.
This is because DOM APIs like document does not exist in a SSR environment. Try running the Locomotive Scroll init code inside a useEffect, so the code that accesses the browser only runs client-side.
As you can see, i use locomotive scroll init wrapper in useEffect
You have to check if document is defined. Then your build will not break.