Use 'use client' or die. #62100
-
|
Guys, I'm tired of it. ContextI'm working in a monorepos to learn few things, the repo is here. In this project, I have a package So, I have a bunch of component in the Here's the thingSometimes, I'm importing a component from a nextjs that dont use any client side api, so I dont have to 'use client' it to make it work. And everything's fine with that, till something like this happen : In this error, in In So, where's the error from ?Just because I dont want to put a 'use client' in the What to do ?Because the 'use client' gymnastic can be fun (maybe) for 5 min, but having this error everytime I make a new component and I forget to wrap and re-export it in nextjs is exhausting. So that's the thing ? Now, you have to 'use client' or be cursed with some annoyng errors ? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
|
I think you could just add That is, if you know a component is using client side or state apis, that make it a client component, you should add |
Beta Was this translation helpful? Give feedback.
-
|
Hi,
One would use a And since It becomes a bit more annoying when barrel files are at play, because those mix concerns from various modules, and, to be honest, I am not 100% cut clear on whether bundlers can, today, see through the barrel file mess, and figure out client usage. Clearly in your case it doesn't, because you are using I can understand the negative to pollute your UI code with One trick, however, silly and dirty, is to re-export on the project. 'use client'
export { AppLogo } from 'ui/common'And yeah it sucks because that AppLogo will ship JavaScript to the client, even if it has no interactivity. I would have expected ESM modules to cut through this one, and only bring the AppLogo though. I am also concerned about this in a couple of projects I am working with. Will monitor this thread for more info. |
Beta Was this translation helpful? Give feedback.
-
|
I discussed this with some people and the misunderstanding is often about the utility (or not) of 'use client' and they tried to explain to me the benefit of understanding the separation between server and client component. My point is much simpler (but stil opinionated), I think 'use client' should be used only where it's important to make the separation. I dont think it has its place in a component library, especially in a monorepos when those components are meant to be use elsewhere, like in a place where thinking of such separation is a non sense (for example a full csr app). |
Beta Was this translation helpful? Give feedback.
Hi,
use clientmeans bundle to ship to a browser. It is a hint to bundlers, amongst other things, but unfortunately, many tech-influencers jumped the gun and used language that made it sound like these are correlated to browser API usage, which is again, not the case.One would use a
use clientdirective to hint at interactivity rather, that this module contains JavaScript that runs client side.And since
useStateand a few others, do need JavaScript to do the state updates and such, you need theuse clientdirective when using them.It becomes a bit more annoying when barrel files are at play, because those mix concerns from various modules, and, to be honest, I am not 100% cut clear on …