Files
next.js/errors/react-client-hook-in-server-component.mdx
T
6f4352993d docs: add and unify notes to error pages (#72838)
## 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]>
2024-11-19 09:44:42 +00:00

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)