Next.js Discord

Discord Forum

Noobie understanding fetching

Unanswered
Tan posted this in #help-forum
Open in Discord
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!

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!
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 ‘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