Noobie understanding fetching
Unanswered
Tan posted this in #help-forum
TanOP
Hi, I could use some help understanding server actions.
If I have a file named actions but it isn’t marked with "use server" at the top, does that mean it’s treated as standard actions that depend on where they are called from? Additionally, if I call these actions from the client, will the fetches be cached on the client side, since they’re not being invoked from the server?
Thanks!
If I have a file named actions but it isn’t marked with "use server" at the top, does that mean it’s treated as standard actions that depend on where they are called from? Additionally, if I call these actions from the client, will the fetches be cached on the client side, since they’re not being invoked from the server?
Thanks!
4 Replies
@Tan Hi, I could use some help understanding server actions.
If I have a file named actions but it isn’t marked with "use server" at the top, does that mean it’s treated as standard actions that depend on where they are called from? Additionally, if I call these actions from the client, will the fetches be cached on the client side, since they’re not being invoked from the server?
Thanks!
Cuban Crocodile
Based on the doc if you want to use server actions you have to add “use server” at the top of the action file. Server actions are called only on the server. You can use fetch or axios to make requests on the client side.
@Tan Hi, I could use some help understanding server actions.
If I have a file named actions but it isn’t marked with "use server" at the top, does that mean it’s treated as standard actions that depend on where they are called from? Additionally, if I call these actions from the client, will the fetches be cached on the client side, since they’re not being invoked from the server?
Thanks!
As said above you must use the ‘use server’ directive at the top of the file to have all exported functions in that file be treated as Server Actions.
The whole point of Server Actions is to call them from the client and have code run on the server, Server Actions are not cached.
The whole point of Server Actions is to call them from the client and have code run on the server, Server Actions are not cached.
The ‘fetch()’ api calls inside Server Actions can be cached and depending on the version of Next.js you are using they will be automatically
TanOP
@Plague
@Cuban Crocodile
thank you so much now that totally make sense
@Cuban Crocodile
thank you so much now that totally make sense