question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created 4 years ago
  • Reactions:5
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
oliviertassinaricommented, Apr 6, 2019

@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.

0reactions
oliviertassinaricommented, Apr 25, 2019
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found