mirror of
https://github.com/vercel/next.js.git
synced 2026-09-20 02:25:18 +08:00
9c757f6d5c
Closes: - https://linear.app/vercel/issue/DOC-4655/client-components - https://linear.app/vercel/issue/DOC-4656/server-components - https://linear.app/vercel/issue/DOC-4657/composition-patterns Redirects: https://github.com/vercel/front/pull/45564 This PR: - Adds new **Server and Client Components** page to **Getting Started** - Explains how Server and Client components are rendered - Clarifies when to use them - Reviews and simplifies composition patterns (examples) - Improves the **How does PPR work** section in light of static, dynamic, and streaming.
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/getting-started/server-and-client-components)
|