Skip to content

Commit e7e567b

Browse files
authored
[docs] Functional syntax for _document example in Basic Features: Font Optimization (vercel#40140)
## Bug - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Errors have helpful link attached, see `contributing.md` ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have helpful link attached, see `contributing.md` ## Documentation / Examples - [X] Make sure the linting passes by running `pnpm lint` - [X] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
1 parent abddee7 commit e7e567b

File tree

1 file changed

+17
-21
lines changed

1 file changed

+17
-21
lines changed

docs/basic-features/font-optimization.md

+17-21
Original file line numberDiff line numberDiff line change
@@ -27,28 +27,24 @@ To add a web font to your Next.js application, add the font to a [Custom `Docume
2727
```js
2828
// pages/_document.js
2929

30-
import Document, { Html, Head, Main, NextScript } from 'next/document'
31-
32-
class MyDocument extends Document {
33-
render() {
34-
return (
35-
<Html>
36-
<Head>
37-
<link
38-
href="https://fonts.googleapis.com/css2?family=Inter&display=optional"
39-
rel="stylesheet"
40-
/>
41-
</Head>
42-
<body>
43-
<Main />
44-
<NextScript />
45-
</body>
46-
</Html>
47-
)
48-
}
30+
import { Html, Head, Main, NextScript } from 'next/document'
31+
32+
export default function Document() {
33+
return (
34+
<Html>
35+
<Head>
36+
<link
37+
href="https://fonts.googleapis.com/css2?family=Inter&display=optional"
38+
rel="stylesheet"
39+
/>
40+
</Head>
41+
<body>
42+
<Main />
43+
<NextScript />
44+
</body>
45+
</Html>
46+
)
4947
}
50-
51-
export default MyDocument
5248
```
5349
5450
Adding fonts to `_document` is preferred over individual pages. When adding fonts to a single page with [`next/head`](/docs/api-reference/next/head.md), font optimizations included by Next.js will not work on navigations between pages client-side or when using [streaming](/docs/advanced-features/react-18/streaming.md).

0 commit comments

Comments
 (0)