Server Actions are functions that execute on the server but are called from the client. Introduced in React 19 + Next.js.
Simple analogy: Imagine you are in a restaurant.
What it looks like in code:
1// In a file with 'use server' marker (separate file)2'use server';34export async function createOrder(formData) {5 const name = formData.get('name');6 const email = formData.get('email');78 // This code executes ON THE SERVER9 await db.orders.create({ name, email });10 await sendEmail(email);11}1213// On the client:14function OrderForm() {15 return (16 <form action={createOrder}> {/* Server function! */}17 <input name="name" required />18 <input name="email" type="email" required />19 <button type="submit">Order</button>20 </form>21 );22}
Advantages: