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

Crash without ThemeProvider #1603

Closed
oliviertassinari opened this issue Mar 26, 2020 · 2 comments · Fixed by #1602
Closed

Crash without ThemeProvider #1603

oliviertassinari opened this issue Mar 26, 2020 · 2 comments · Fixed by #1602
Labels
bug 🐛 Something isn't working good first issue Great for newcomers
Milestone

Comments

@oliviertassinari
Copy link
Member

TypeError: Cannot read property 'breakpoints' of null

The problems originate from this line

https://github.com/mui-org/material-ui-pickers/blob/0d41c48aaa8b9b6f67e72deee9583340cd218b89/lib/src/wrappers/ResponsiveWrapper.tsx#L27

For more details: mui/material-ui#16859

Environment

Tech Version
@material-ui/pickers v4.0.0-alpha.4

Steps to reproduce

https://codesandbox.io/s/cranky-hamilton-130yq

@oliviertassinari oliviertassinari added the bug 🐛 Something isn't working label Mar 26, 2020
@dmtrKovalenko
Copy link
Member

Thanks @oliviertassinari!
AFAI we need to make our own custom version of this hook?

@oliviertassinari
Copy link
Member Author

@dmtrKovalenko I propose this patch:

diff --git a/lib/src/wrappers/ResponsiveWrapper.tsx b/lib/src/wrappers/ResponsiveWrapper.tsx
index adb9def4..c5e69dc3 100644
--- a/lib/src/wrappers/ResponsiveWrapper.tsx
+++ b/lib/src/wrappers/ResponsiveWrapper.tsx
@@ -1,5 +1,5 @@
 import * as React from 'react';
-import { Theme } from '@material-ui/core/styles';
+import { useTheme } from '@material-ui/core/styles';
 import useMediaQuery from '@material-ui/core/useMediaQuery';
 import { MobileWrapperProps, MobileWrapper } from './MobileWrapper';
 import { DesktopWrapperProps, DesktopWrapper } from './DesktopWrapper';
@@ -24,7 +24,8 @@ export const ResponsiveWrapper: React.FC<ResponsiveWrapperProps> = ({
   PopoverProps,
   ...other
 }) => {
-  const isDesktop = useMediaQuery<Theme>(theme => theme.breakpoints.up(desktopModeBreakpoint));
+  const theme = useTheme();
+  const isDesktop = useMediaQuery(theme.breakpoints.up(desktopModeBreakpoint));

   return isDesktop ? (
     <DesktopWrapper PopoverProps={PopoverProps} {...other} />

@oliviertassinari oliviertassinari added the good first issue Great for newcomers label Mar 31, 2020
@oliviertassinari oliviertassinari added this to the v4 milestone Apr 6, 2020
@oliviertassinari oliviertassinari modified the milestones: v4, v5 Jul 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something isn't working good first issue Great for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants