DEV Community

Discussion on: Next.js: how to access browser "window" object

Collapse
 
rafde profile image
Rafael De Leon

I think you can also do
globalThis?.window?.innerWidth
or
window?.innerWidth

I usually do the first one to be formal

Collapse
 
ivan_jrmc profile image
Ivan Jeremic

do you do

if (typeof globalThis?.window?.innerWidth !== "undefined") {
   var width = window.innerWidth;     
}
Enter fullscreen mode Exit fullscreen mode

or

if (globalThis?.window?.innerWidth) {
   var width = window.innerWidth;     
}
Enter fullscreen mode Exit fullscreen mode


?