Perhaps like this?
const isBrowser = () => typeof window !== "undefined" // node isBrowser() // false // browser isBrowser() // true
Yes that would work indeed! Thanks :)
Just added a new solution and thank you note :)
In a tread related to this problem in Next.JS official GitHub issue page mentioned that it is wrong to do so and you need to explicitly check typeof window !== "undefined" wherever you need it: NextJS GitHub issues page
typeof window !== "undefined"
Consider reading my solution as well. it's inspirred by this post. So thank you Vincent for idea. NextJS - Access window and localStorage
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Perhaps like this?
Yes that would work indeed! Thanks :)
Just added a new solution and thank you note :)
In a tread related to this problem in Next.JS official GitHub issue page mentioned that it is wrong to do so and you need to explicitly check
typeof window !== "undefined"wherever you need it:NextJS GitHub issues page
Consider reading my solution as well. it's inspirred by this post. So thank you Vincent for idea.
NextJS - Access window and localStorage