Skip to content

Commit fae30f9

Browse files
authored
[docs] Add Next.js App Router guide for custom classnames (#45852)
1 parent e7728bb commit fae30f9

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

docs/data/material/experimental-api/classname-generator/classname-generator.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,16 +124,36 @@ Always create an initializer file to hoist the `ClassNameGenerator` call to the
124124

125125
```js
126126
// create a new file called `MuiClassNameSetup.js` at the root or src folder.
127+
'use client'; // remove this line if you are not using React Server Components
127128
import { unstable_ClassNameGenerator as ClassNameGenerator } from '@mui/material/className';
128129

129130
ClassNameGenerator.configure(
130131
// Do something with the componentName
131132
(componentName) => componentName,
132133
);
134+
135+
export default null;
133136
```
134137

135138
Then import the file in the main JavaScript source based on the framework.
136139

140+
### Next.js App Router
141+
142+
Add the `'use client'` directive and import the initializer in `/app/page.js`.
143+
144+
```diff
145+
+'use client';
146+
+import './MuiClassNameSetup';
147+
import * as React from 'react';
148+
import Button from '@mui/material/Button';
149+
150+
export default function Page() {
151+
return (
152+
<Button>Text</Button>
153+
);
154+
}
155+
```
156+
137157
### Next.js Pages Router
138158

139159
Import the initializer in `/pages/_app.js`.

0 commit comments

Comments
 (0)