How do I use Media Queries in the Next.js App Router?
I am using Next.js 13 with the App Router and have the following client component, which uses media queries inside the javascript to display a sidebar differently for small/big screens. "use client"; export default function Feed() { const [isLargeScreen, setIsLargeScreen] = useState(window.matchMedia("(min-width: 768px)").matches); useEffect(() => { window .matchMedia("(min-width: 1024px)") .addEventListener('change', e => setIsLargeScreen(e.matches)); }, []); return ( <div> <Sidebar isLargeScreen={isLargeScreen}/> <div>...</div> </div> ) } Now, the site loads inside the client perfectly, but
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.