Skip to content

Commit

Permalink
[docs] Fix useMediaQuery SSR example to v5 theme API (mui#30454)
Browse files Browse the repository at this point in the history
  • Loading branch information
ValentinH authored and wladimirguerra committed Feb 2, 2022
1 parent 30c5aca commit e9228df
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions docs/src/pages/components/use-media-query/use-media-query.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ For instance on the server-side:
import ReactDOMServer from 'react-dom/server';
import parser from 'ua-parser-js';
import mediaQuery from 'css-mediaquery';
import { ThemeProvider } from '@mui/material/styles';
import { createTheme, ThemeProvider } from '@mui/material/styles';

function handleRender(req, res) {
const deviceType = parser(req.headers['user-agent']).device.type || 'desktop';
Expand All @@ -155,17 +155,19 @@ function handleRender(req, res) {
}),
});

const html = ReactDOMServer.renderToString(
<ThemeProvider
theme={{
props: {
// Change the default options of useMediaQuery
MuiUseMediaQuery: {
ssrMatchMedia,
},
const theme = createTheme({
components: {
// Change the default options of useMediaQuery
MuiUseMediaQuery: {
defaultProps: {
ssrMatchMedia,
},
}}
>
},
},
});

const html = ReactDOMServer.renderToString(
<ThemeProvider theme={theme}>
<App />
</ThemeProvider>,
);
Expand Down

0 comments on commit e9228df

Please sign in to comment.