vercel/next.js / errors / react-client-hook-in-server-component.mdx
The React Framework
react-client-hook-in-server-component.mdx
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
import { useEffect } from 'react'
export default function Example() {
useEffect(() => {
console.log('in useEffect')
})
return <p>Hello world</p>
}
After
'use client'
import { useEffect } from 'react'
export default function Example() {
useEffect(() => {
console.log('in useEffect')
})
return <p>Hello world</p>
}
Useful Links
Rendered from the public repository vercel/next.js on GitHub; content belongs to its authors. Cached for up to an hour.