Skip to content

Commit cb3d718

Browse files
[material-ui][docs] Polish the Next.js integration page (#40317)
Signed-off-by: Olivier Tassinari <olivier.tassinari@gmail.com> Co-authored-by: Danilo Leal <67129314+danilo-leal@users.noreply.github.com>
1 parent e13f5d0 commit cb3d718

File tree

5 files changed

+22
-14
lines changed

5 files changed

+22
-14
lines changed

docs/data/material/guides/nextjs/nextjs.md

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Next.js Integration
1+
# Next.js integration
22

33
<p class="description">Learn how to use Material UI with Next.js</p>
44

@@ -32,8 +32,8 @@ pnpm add @mui/material-nextjs @emotion/cache
3232
Inside `app/layout.tsx`, import the `AppRouterCacheProvider` and wrap all elements under the `<body>` with it:
3333

3434
```diff
35-
// app/layout.tsx
36-
+ import { AppRouterCacheProvider } from '@mui/material-nextjs/v13-appRouter'; // or `v14-appRouter` if you are using Next.js v14
35+
+import { AppRouterCacheProvider } from '@mui/material-nextjs/v13-appRouter';
36+
// or `v1X-appRouter` if you are using Next.js v1X
3737

3838
export default function RootLayout(props) {
3939
const { children } = props;
@@ -92,7 +92,11 @@ Inside the `pages/_document.tsx` file:
9292
- Import `DocumentHeadTags` and render it inside the `<Head>`.
9393

9494
```diff
95-
+ import { DocumentHeadTags, documentGetInitialProps } from '@mui/material-nextjs/v13-pagesRouter'; // or `v14-pagesRouter` if you are using Next.js v14
95+
+import {
96+
+ DocumentHeadTags,
97+
+ documentGetInitialProps,
98+
+} from '@mui/material-nextjs/v13-pagesRouter';
99+
// or `v1X-pagesRouter` if you are using Next.js v1X
96100

97101
export default function MyDocument(props) {
98102
return (
@@ -109,13 +113,17 @@ Inside the `pages/_document.tsx` file:
109113
);
110114
}
111115

112-
+ MyDocument.getInitialProps = documentGetInitialProps;
116+
+MyDocument.getInitialProps = async (ctx) => {
117+
+ const finalProps = await documentGetInitialProps(ctx);
118+
+ return finalProps;
119+
+};
113120
```
114121

115122
Then, inside `pages/_app.tsx`, import the `AppCacheProvider` component and render it as the root element:
116123

117124
```diff
118-
+ import { AppCacheProvider } from '@mui/material-nextjs/v13-pagesRouter'; // or `v14-pages` if you are using Next.js v14
125+
+import { AppCacheProvider } from '@mui/material-nextjs/v13-pagesRouter';
126+
// Or `v1X-pages` if you are using Next.js v1X
119127

120128
export default function MyApp(props) {
121129
return (
@@ -134,7 +142,8 @@ Then, inside `pages/_app.tsx`, import the `AppCacheProvider` component and rende
134142
If you are using TypeScript, add `DocumentHeadTagsProps` to the Document's props interface:
135143

136144
```diff
137-
+ import type { DocumentHeadTagsProps } from '@mui/material-nextjs/v13-pagesRouter'; // or `v14-pagesRouter` if you are using Next.js v14
145+
+ import type { DocumentHeadTagsProps } from '@mui/material-nextjs/v13-pagesRouter';
146+
// or `v1X-pagesRouter` if you are using Next.js v1X
138147

139148
+ export default function MyDocument(props: DocumentProps & DocumentHeadTagsProps) {
140149
...

docs/data/material/pages.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ const pages: MuiPage[] = [
207207
{ pathname: '/material-ui/guides/shadow-dom', title: 'Shadow DOM' },
208208
{
209209
pathname: '/material-ui/guides/nextjs',
210-
title: 'Next.js Integration',
210+
title: 'Next.js integration',
211211
newFeature: true,
212212
},
213213
],

docs/translations/translations.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@
454454
"/material-ui/guides/content-security-policy": "Content Security Policy",
455455
"/material-ui/guides/right-to-left": "Right-to-left",
456456
"/material-ui/guides/shadow-dom": "Shadow DOM",
457-
"/material-ui/guides/nextjs": "Next.js Integration",
457+
"/material-ui/guides/nextjs": "Next.js integration",
458458
"/material-ui/experimental-api": "Experimental APIs",
459459
"/material-ui/experimental-api/classname-generator": "ClassName generator",
460460
"CSS theme variables": "CSS theme variables",
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# @mui/material-nextjs
22

3-
The official integration of Material-UI with Next.js. For full documentation, visit [Next.js Integration](material-ui/guides/nextjs/) page.
3+
The official Material UI integration with Next.js. For the full documentation, visit [Next.js integration](https://mui.com/material-ui/guides/nextjs/) page.

packages/mui-material-nextjs/package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
"description": "Collection of utilities for integration between Material UI and Next.js.",
77
"keywords": [
88
"react",
9-
"react-component",
10-
"mui",
11-
"utils"
9+
"next",
10+
"material-ui"
1211
],
1312
"repository": {
1413
"type": "git",
@@ -19,7 +18,7 @@
1918
"bugs": {
2019
"url": "https://github.com/mui/material-ui/issues"
2120
},
22-
"homepage": "private package",
21+
"homepage": "https://mui.com/material-ui/guides/nextjs/",
2322
"funding": {
2423
"type": "opencollective",
2524
"url": "https://opencollective.com/mui-org"

0 commit comments

Comments
 (0)