Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When I refresh the page useMedia will break my UI (Remove css) #1885

Open
jemink opened this issue Mar 16, 2021 · 5 comments
Open

When I refresh the page useMedia will break my UI (Remove css) #1885

jemink opened this issue Mar 16, 2021 · 5 comments

Comments

@jemink
Copy link

jemink commented Mar 16, 2021

I implemented useMedia() from react-use so when I check desktop to mobile then it is working fine but when I refresh on mobile then it will remove my css

**
import React, { FC } from 'react'
import { useMedia } from 'react-use'

const Index: FC = () => {
const isMobile = useMedia('(max-width: 768px)', false);

return (


{isMobile ? (
Mobile View
) : (
Desktop View
)}

)
}

.mobile-view {
background-color: aquamarine !important;
}

.desktop-view {
background-color: red;
}
**

Bug issue video:- https://www.awesomescreenshot.com/video/3078205?key=fd357595486a738f6fff5fea636a7597

Version

  • "less": "^3.13.0"
  • "react": "17.0.1"
  • "react-use": "^17.1.1"
  • "next": "10.0.7"
@jemink
Copy link
Author

jemink commented Mar 16, 2021

In above video you can see that when I refresh on the mobile view it will apply style of desktop view that is background-color: red;

@nghiepdev
Copy link

@jemink

Maybe it's because of React 16's new SSR strategy? facebook/react#10591.
And in PR useMedia - initialize state with call to media query make initialize state difference on server and client.

@garryburch
Copy link

Same issue here

@arifintajul4
Copy link

same to me

@mvshmakov
Copy link

Shouldn't this issue be closed with #2216?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants