Closed jslyonnais closed 6 years ago
Just clarifying, this is code executed by the browser, correct? Because Gatsby is a server side renderer, so if you're rendering on node, window won't be defined. Just want to make sure we're on the same page.
Finally found a workaround. You got right about Gatsby, but I was thinking if I can find a way to make things work.
Comment for futur people, finally I've use scrollama
directly from npm, and call it on the componentDidMount
of react.
componentDidMount() {
// Loading module that require "window" to be defined
require('intersection-observer')
const scrollama = require('scrollama')
const scrollThreshold = 0.33
const scroller = scrollama()
scroller.setup({
// debug: true,
step: '.scroll__step',
threshold: scrollThreshold,
container: '.scroll__container',
graphic: '.scroll__graphic'
}).onStepEnter(this.handleScrollStepEnter)
}
Great! Thanks for posting your solution.
Webpack production build using Gatsby return
WebpackError: ReferenceError: window is not defined
. Should make sure window is define before loadingintersection-oberver
. Will also make other window usage in scrollama.js works with that mechanic.