"use server" file vs "use server" function
Hi all,
I just have a question about the behaviour of "use server" for a single function vs "use server" for a whole file..
I have a sign-up component that imports an action from my api:
Here is a working version of said action (note that this is the entire contents of the file) :
What doesn't work, is when I move the "use server" directive to the top of the file instead of for just the function. When I do this, I'm redirected to
https://action/userSignUp
(see attached image).
The "use server" documentation page doesn't seem to answer why this would be happening. Is this expected behaviour? And if so, could someone please explain to me why this is happening so I can better understand it?
2 Replies
The thing is that the
action
itself (its function) gets called on the client. This also applies to functions wrapped in query
.
you may use the "use server" directive only for the functions inside those helpersAhh, yes ok that makes sense. Thanks for the explanation