yocontra / react-responsive

CSS media queries in react - for responsive design, and more.
https://contra.io/react-responsive
MIT License
7.04k stars 298 forks source link

NextJS SSR #239

Closed tomflorentin closed 4 years ago

tomflorentin commented 4 years ago

Does not work with next JS server side rendering

  const isDesktop = useMediaQuery({ minDeviceWidth: 600 });
  console.log("Render : " + isDesktop);
  console.log("JustifyContent : " + (isDesktop ? "space-between" : "center"));

In the server console :

Render : false JustifyContent : center

while i'm using a desktop browser.

yocontra commented 4 years ago

Can you post an example repo or codepen/jsfiddle/etc. that reproduces the issue?

nhuanhoangduc commented 4 years ago

This is how I solved ssr issue: code

yocontra commented 4 years ago

Going to fold this into #162 since its the same issue

maximgeerinck commented 2 years ago

This is how I solved ssr issue: code

This works, however i also had to add key={isClient ? 0 : 1} to make sure it remounts the component (only for when you rely on init props )