-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
useMediaQuery does not play well with dynamic components in Next.js #35891
Comments
@yjoer would you like to submit PR with the proposed fix? We could try using |
After digging for a while, I have confirmed that this has nothing to do with
|
I faced the same problem |
workaround import { useMediaQuery } from '@react-hookz/web';
export function useSidebarFloating() {
const theme = useTheme();
return (
useMediaQuery(theme.breakpoints.down('md').replace(/^@media( ?)/m, '')) ??
false
);
} |
I believe mui returns some extra string in breakpoints. You should check it and use regex to remove extra content |
Duplicates
Latest version
Steps to reproduce 🕹
Link to live example:
https://codesandbox.io/p/sandbox/usemediaquery-and-suspense-ipi2y0
Steps:
useLayoutEffect
https://ipi2y0-3000.preview.csb.app/possible-cause.useLayoutEffect
is the root cause in this case, a possible fix is to wrap these functions instartTransition
as in https://ipi2y0-3000.preview.csb.app/possible-fixCurrent behavior 😯
Next.js emits the following error when
useMediaQuery
is used in a component with dynamically imported components.Expected behavior 🤔
There should not be any errors when using the hook with dynamically imported components.
Context 🔦
I am using
useMediaQuery
in a component with lazy-loaded components.Your environment 🌎
npx @mui/envinfo
The text was updated successfully, but these errors were encountered: