mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
## Description Unify the note format according to the [contribution guide](https://nextjs.org/docs/community/contribution-guide#notes). In addition, add missing bullet points to useful links. ### 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]>
44 lines
807 B
Plaintext
44 lines
807 B
Plaintext
---
|
|
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/building-your-application/rendering/server-components)
|