react nextjs isMobile on statically generated pages

most solutions you'll find for determining whether a user is viewing your web app on mobile will not work on statically generated pages

this is the cleanest solution i could come up with

const [isMobile, setIsMobile] = React.useState<number>(false);

React.useEffect(() => {
  setIsMobile(window.innerWidth < 700);
}, []);

return isMobile ? <h1>mobile</h1> : <h1>desktop</h1>

this works because useEffect is a method that is only run client-side

✌️