fix: window is not available during gatsby build

Check if window is available, and set initial value for `state.scrollY`.
This commit is contained in:
jumpyapple
2021-06-01 00:02:56 -04:00
committed by Jean-Philippe Sirois
parent 38e1a4ba56
commit 5ba1e86672
+3 -1
View File
@@ -39,7 +39,6 @@ const BoxedTitle: React.FC<IBoxedTitleProps> = (props) => {
) )
} }
const debounce = (fn) => { const debounce = (fn) => {
let frame let frame
return (...params) => { return (...params) => {
@@ -57,13 +56,16 @@ export class HeaderBarebone extends Component<IHeaderBareboneProps, HeaderBarebo
constructor(props) { constructor(props) {
super(props) super(props)
this.tick = this.tick.bind(this) this.tick = this.tick.bind(this)
this.state = { scrollY: 0 }
} }
tick() { tick() {
if (typeof window !== 'undefined') {
this.setState({ this.setState({
scrollY: window.scrollY scrollY: window.scrollY
}) })
} }
}
componentWillMount() { componentWillMount() {
this.tick() this.tick()