silverwolf-x/project / errors /react-client-hook-in-server-component.mdx
silverwolf-x's picture
download
raw
798 Bytes
---
title: React client hook in Server Component
---
## Why This Error Occurred
You are using a React client hook in a Server Component.
## Possible Ways to Fix It
Mark the component using the hook as a Client Component by adding `'use client'` at the top of the file.
### Before
```jsx filename="app/example.js"
import { useEffect } from 'react'
export default function Example() {
useEffect(() => {
console.log('in useEffect')
})
return <p>Hello world</p>
}
```
### After
```jsx filename="app/example.js"
'use client'
import { useEffect } from 'react'
export default function Example() {
useEffect(() => {
console.log('in useEffect')
})
return <p>Hello world</p>
}
```
## Useful Links
- [Server Components](/docs/app/getting-started/server-and-client-components)

Xet Storage Details

Size:
798 Bytes
·
Xet hash:
90b52cab4cebe24a35f48483fccd54559b21543e42273d84a1a5624cf369ad85

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.