Why do nextjs enforce putting `use client` at the top of the file?

I have learned the difference between server component and client component. I do not want to put use client at the top of a file to mark all components inside as client components, so I only put it in the components that use any hooks. However, after I did this, nextjs complained that when I import some hooks from nextjs, I didn’t put use client at the top of the file, even I have put it in the client components.

This surprised me, because importing react hooks does not enforce me to do that.

I thought use client is like use server that it can be used in a component, but I am wrong. Anyway, React directive design breaks too many pricinples of the astonishment.

Thank you for sharing what worked for you :slight_smile:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.