Performance: Why server actions simplify mutations
MEDIUM IMPACT
This concept affects interaction responsiveness and reduces client-side bundle size by moving mutation logic to the server.
'use server'; export async function increment() { // Server-side mutation logic await db.incrementCounter(); } export default function Counter() { return <form action={increment}> <button type="submit">Increment</button> </form>; }
import { useState } from 'react'; export default function Counter() { const [count, setCount] = useState(0); async function increment() { // Client-side mutation with fetch await fetch('/api/increment', { method: 'POST' }); setCount(count + 1); } return <button onClick={increment}>Count: {count}</button>; }
| Pattern | Client Bundle Size | Network Requests | Input Responsiveness | Verdict |
|---|---|---|---|---|
| Client-side mutation with fetch | Larger (+5-10kb) | Multiple requests | Slower due to fetch wait | [X] Bad |
| Server actions for mutations | Smaller (saves 5-10kb) | Fewer requests, form submit | Faster input response | [OK] Good |