How do I use useMediaQuery only on the client when using NextJS? #3437
Answered
by
turtletongue
turtletongue
asked this question in
Q&A
-
I am using NextJS and have encountered an error. |
Beta Was this translation helpful? Give feedback.
Answered by
turtletongue
Apr 19, 2024
Replies: 1 comment 4 replies
-
I have solved this problem!! With the help of next/dynamic and { ssr: false } |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@mercurymirror you don't need to use dynamic for useMediaQuery. To solve this problem I used dynamic import for component where useMediaQuery was called.
example-component.tsx
page.tsx
But I don't think now that using useMediaQuery is a good idea with NextJS. I think it's better to use Chakra layouts such as flex and grid to make your website responsive because you'll have advantages of server side…