window is not defined
React and NextJS can throw some interesting problems
When working with React and NextJS, sometimes you’re likely to see `window is not defined` errors. This is because the window object isn’t defined when the code is executed. Sometimes with JS, you wish it would just shut the hell up because of it’s dynamic nature, but alas, it doesn’t and you have to deal with it.
Mixing JavaScript and React has caused me headaches before and sometimes I forget that React is just a set of opinions on JavaScript. NextJS in my opinion is even more opinionated and righteous, and how you solve this problem depends on how you’re invoking the problem, but for me, it’s normally a case of using `useEffect()`.
Vincent Voyer’s excellent post is here: https://dev.to/vvo/how-to-solve-window-is-not-defined-errors-in-react-and-next-js-5f97