Provide a better example for `useMediaQuery` for SSR usage.
See original GitHub issue- This is not a v0.x issue.
- I have searched the issues of this repository and believe that this is not a duplicate.
Expected Behavior 🤔
The documentation should give a better example on how to implement useMediaQuery with SSR.
Current Behavior 😯
Right now, it only says this and a vage example
An implementation of matchMedia is required on the server, we recommend using css-mediaquery. We also encourage the usage of the unstable_useMediaQueryTheme version of the hook that fetches properties from the theme. This way, you can provide a ssrMatchMedia option once for all your React tree.
I think it should give an example on how to use ssrMatchMedia, and specially, how to set the initial width (given in the example) with common SSR tools, such as NextJS, Razzle or Gatsby.
Right now, I wasn’t able to make this example work, but if I can, I’ll gladly create a PR to complete this documentation page.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:5
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Provide a better example for `useMediaQuery` for SSR usage.
The documentation should give a better example on how to implement useMediaQuery with SSR. Current Behavior. Right now, it only says this and ......
Read more >`useMediaQuery`hook that actually works with SSR : r/nextjs
I use the media query in such way because my desktop and mobile components have the exact same content but are layed out...
Read more >useMediaQuery - Chakra UI
The useMediaQuery hook accepts a single media query or an array of media queries, and optionally an object that contains an ssr boolean...
Read more >Media queries in React for responsive design - Material UI - MUI
useMediaQuery. This is a CSS media query hook for React. It listens for matches to a CSS media query. It allows the rendering...
Read more >How to implement SSR for Material UI's media queries in ...
First a caveat -- I do not currently have any experience using SSR myself, but I have deep knowledge of Material-UI and I...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@charlie632 You are right, the documentation for it is minimal. I was lazy when writing this piece of documentation. I wanted to highlight the fact that it’s technically possible. The tests of the component can help. They show how you can use it on the server once you know the client width. To get the client width, you can use a user agent conversion library or HTTP client hints.
It’s not a simple problem. If you can avoid it, its even better.
@rviderman Do you try using CSS media queries? https://next.material-ui.com/layout/breakpoints/#css-media-queries