Skip to content

Commit 7cf2a54

Browse files
author
Jason Frank
committed
Fixed MUI console warning that shows in dev
1 parent 582171a commit 7cf2a54

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

components/videoArea.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,12 @@ export default function VideoArea({
8080
</span>
8181
</VideosContainer>
8282

83-
<Button variant="outlined" onClick={handleWebcamBtnClick}>Start webcam</Button>
83+
<Button
84+
color="primary"
85+
variant="outlined"
86+
onClick={handleWebcamBtnClick}>
87+
Start webcam
88+
</Button>
8489

8590

8691
<Dialog open={isWebcamDialogOpen}>

pages/_app.js

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
import { createGlobalStyle, ThemeProvider } from 'styled-components';
2+
import { createMuiTheme, MuiThemeProvider } from '@material-ui/core';
3+
import { unstable_createMuiStrictModeTheme } from '@material-ui/core';
4+
5+
26

37
const GlobalStyle = createGlobalStyle`
48
html,
@@ -23,19 +27,37 @@ const GlobalStyle = createGlobalStyle`
2327
}
2428
`;
2529

26-
const theme = {
30+
const styledComponentsTheme = {
2731
colors: {
2832
primary: '#0070f3'
2933
}
3034
};
3135

36+
console.log("In _app.js, process.env.NODE_ENV: ");
37+
console.log(process.env.NODE_ENV);
38+
39+
const createMuiThemeForEnvironment =
40+
process.env.NODE_ENV === 'production' ?
41+
createMuiTheme :
42+
// For dev environments, we need to use a newer version that solves the strict mode console warning for components like the Dialog. See: https://github.com/mui-org/material-ui/issues/13394#issuecomment-815452717
43+
unstable_createMuiStrictModeTheme;
44+
45+
const muiTheme = createMuiThemeForEnvironment({
46+
palette: {
47+
primary: {
48+
main: styledComponentsTheme.colors.primary
49+
}
50+
}
51+
});
3252

3353
function MyApp({ Component, pageProps }) {
3454
return (
3555
<>
3656
<GlobalStyle />
37-
<ThemeProvider theme={theme}>
38-
<Component {...pageProps} />
57+
<ThemeProvider theme={styledComponentsTheme}>
58+
<MuiThemeProvider theme={muiTheme} >
59+
<Component {...pageProps} />
60+
</MuiThemeProvider>
3961
</ThemeProvider>
4062
</>
4163
);

0 commit comments

Comments
 (0)