'windows is undefined while using react-sweet-state with nextjs

I am getting a windows is undefined error while using react-sweet-state with nextjs.
I have seen similar nextjs issues and the recommended solution was to use a rendering condition typeof window === undefined. I cannot use that rendering condition because I need the app to load even when the window is undefined.

Is there any other way to resolve the issue ?

Edit: I have added some code here which may help

pages/article/[id].js

const Article = () => {

  //                         here is where i get the 'windows is undefined' error
  const [{ article }, { fetchArticleData }] = useArticleStore();
  
  return (
    <>
      <Head>
        <meta property="og:title" name="og:title" content={article.title} />
        <meta property="og:description" name="og:description" content={article.desc} />
      </Head>
      <article>
        <h1>{ article.title }</h1>
        <p 
          dangerouslySetInnerHTML={{ __html: article.content }}
        ></p>
    </>
  )
 }

pages/_app.js
import "antd/dist/antd.css";
import "../styles/globals.scss";

import Layout from "../layout";

const App = ({ Component, pageProps }) => {
  return (
    <Layout>
      <div suppressHydrationWarning>
        {typeof window === "undefined" ? null : <Component {...pageProps} />}
      </div>
    </Layout>
  );
};

export default App;


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source