File size: 1,083 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
---
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)
|