locomotive-scroll icon indicating copy to clipboard operation
locomotive-scroll copied to clipboard

Locomotive scroll with typescript

Open natainditama opened this issue 2 years ago • 4 comments

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.

gambar

natainditama avatar Jun 18 '22 09:06 natainditama

I'm always frustrated when looking for such problems.

natainditama avatar Jun 18 '22 09:06 natainditama

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.

iojcde avatar Jun 19 '22 00:06 iojcde

gambar As you can see, i use locomotive scroll init wrapper in useEffect

natainditama avatar Jun 27 '22 06:06 natainditama

You have to check if document is defined. Then your build will not break.

ghost avatar Jul 01 '22 07:07 ghost