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
+6 -4
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,12 +56,15 @@ 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() {
this.setState({ if (typeof window !== 'undefined') {
scrollY: window.scrollY this.setState({
}) scrollY: window.scrollY
})
}
} }
componentWillMount() { componentWillMount() {