Built.fm

Share this post

window is not defined

built.fm

window is not defined

React and NextJS can throw some interesting problems

David Gee
Nov 2, 2022
Share this post

window is not defined

built.fm

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

Thanks for reading Built.fm! Subscribe for free to receive new posts and support my work.

Share this post

window is not defined

built.fm
Comments
TopNew

No posts

Ready for more?

© 2023 David Gee
Privacy ∙ Terms ∙ Collection notice
Start WritingGet the app
Substack is the home for great writing