Why Next 13.4 wants me to add "use-client" to a custom hook? #50549
-
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 14 replies
-
Hi, according to the documentation, all hooks should only work on the client. At the specified link, some patterns are also written that can help in development. |
Beta Was this translation helpful? Give feedback.
-
Interactivity is only available client side, so a module that wants to do any sort of interactivity has to be a You have to think in terms of module graph, rather than component graph.
|
Beta Was this translation helpful? Give feedback.
-
I have huge amount of such modules, and adding to all of them "use client" seems ... bad 💀 |
Beta Was this translation helpful? Give feedback.
-
I've found the solution. For me it happened because of barrel files. These are the index.ts files thats sole purpose is to re-export other exports nested deeper in the folder tree. They seem handy to make imports shorter but when you use the short import it actually loads everything from that file. So if you re-export constants, helpers and hooks from a barrel file and you import one of the constants in a server component it will try to load all your hooks too! And of course it fails. I hope this helped! |
Beta Was this translation helpful? Give feedback.
Yeah but you have
import { colors } "@core";
which I guess touches a filecore/index.ts
, which in turn probably, importsuseOpen
, somehow, right?So my question: Do you export other things from the module? is kind of true, you are importing this hook into page, albeit not directly, but through a barrel file of sorts, right?