mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
## Summary Remove redundant `#` from [error pages](https://github.com/vercel/next.js/tree/canary/errors). ## Description Follow up #52038 and #72263. Updated [template.txt](https://github.com/vercel/next.js/blob/canary/errors/template.txt) and clarified the header deps. Then rewrite as per the template. ### Improving Documentation - [x] Run `pnpm prettier-fix` to fix formatting issues before opening the PR. - [x] Read the Docs Contribution Guide to ensure your contribution follows the docs guidelines: https://nextjs.org/docs/community/contribution-guide Co-authored-by: Delba de Oliveira <[email protected]>
58 lines
1.1 KiB
Plaintext
58 lines
1.1 KiB
Plaintext
---
|
|
title: React Class component rendered in a Server Component
|
|
---
|
|
|
|
## Why This Error Occurred
|
|
|
|
You are rendering a React Class Component in a Server Component, `React.Component` and `React.PureComponent` only works in Client Components.
|
|
|
|
## Possible Ways to Fix It
|
|
|
|
Use a Function Component.
|
|
|
|
### Before
|
|
|
|
```jsx filename="app/page.js"
|
|
export default class Page extends React.Component {
|
|
render() {
|
|
return <p>Hello world</p>
|
|
}
|
|
}
|
|
```
|
|
|
|
### After
|
|
|
|
```jsx filename="app/page.js"
|
|
export default function Page() {
|
|
return <p>Hello world</p>
|
|
}
|
|
```
|
|
|
|
Mark the component rendering the React Class Component as a Client Component by adding `'use client'` at the top of the file.
|
|
|
|
### Before
|
|
|
|
```jsx filename="app/page.js"
|
|
export default class Page extends React.Component {
|
|
render() {
|
|
return <p>Hello world</p>
|
|
}
|
|
}
|
|
```
|
|
|
|
### After
|
|
|
|
```jsx filename="app/page.js"
|
|
'use client'
|
|
|
|
export default class Page extends React.Component {
|
|
render() {
|
|
return <p>Hello world</p>
|
|
}
|
|
}
|
|
```
|
|
|
|
## Useful Links
|
|
|
|
[Server Components](/docs/app/building-your-application/rendering/server-components)
|