What happens if I call a server action in a server component?
Answered
Papillon posted this in #help-forum
PapillonOP
I know you're allowed to call a server action from a server component, but if you do this, will Nextjs invoke the action via an RPC call (like it would for a client component invocation)? Or will it just import the server action as standard JS and run the function on the same server that the server component is being rendered in?
Basically, trying to figure out if there's any functional or performance difference between having something like this:
and this:
Basically, trying to figure out if there's any functional or performance difference between having something like this:
// File actions.ts
"use server"
export const func = async () => {
return "Hello World"
}
// File component.ts
import {func} from "actions";
export const component = async () => {
const greeting = await func();
return <h1>{greeting}</h1>
} and this:
// File component.ts
const func = async () => {
return "Hello World"
}
export const component = async () => {
const greeting = await func();
return <h1>{greeting}</h1>
}