Normally, disabling scrolling on the body element can be achieved by toggling a class or overflow property when a mobile menu or modal is open. However, due to Next.js being rendered server-side, accessing the document object is not possible. How can I prevent body scroll when the mobile navigation menu is open in Next.js?
I attempted to access the document object to toggle overlay hidden, but because Next.js is rendered server-side, the document object is unavailable at that stage.
I also experimented with using state and passing it into the navigation component to control the styles, but encountered an issue as useState cannot be used at the top level of the application.