I am trying to change the structure of my app using DOM media queries inside Next.js. Normal media queries (CSS) work no problem. In "pure" React, I could do something like this:
function HomePage () {
const [landscape, setLandscape] = useState(false)
useEffect(() => {
const landscapeHandler = e => {
console.log ("Change in landscape")
setLandscape({matches: e.matches});
}
window.matchMedia("((orientation:landscape)").addEventListener('change', landscapeHandler);
return () => {
window.removeEventListener('change', landscapeHandler);
}
}, [])
}
However, when using Next, changing the orientation of the screen doesn't do anything at all. Is there a workaround? I always thought useEffect is client-side only and therefore the right place to do such media queries... Many thanks in advance!