我们知道可以通过动态引入让其他组件在本组件使用关闭SSR。
import dynamic from 'next/dynamic'
const MyComponentNoSSR = dynamic(() => import('my-component'), {
ssr: false,
})
const App= ({ data }) => {
return (
<>
<MyComponentNoSSR/>
</>
)
}
但是如果我自己定义组件的时候:
是否可以在当前的组件中关闭SSR呢?
const IndexPage = () => {
return (
<div>
data...
</div>
)
}
'use client';
放到你的组件最上面。这个表示就是客服端渲染,