Use window object in Gatsby

if (typeof window !== 'undefined') {
    // ...
}