Skip to content

TypeScript · architecture

prefer-server-actions

eslint:prefer-server-actions

Prefer Next.js Server Actions over /api/* mutations.

Default
error
Fix
none
Languages
typescript

Why

Server Actions preserve typed application calls and avoid an internal JSON request-response boundary.

Fix

Move the mutation into a Server Action and invoke that action from the React client.

Before / after

Executed by this rule’s unit tests.

Before

Do not mutate through an API route

app/tasks/page.tsx · focus
await fetch('/api/tasks', { method: 'POST', body });

After

Call a Server Action

app/tasks/page.tsx · focus
import { createTask } from './actions'; await createTask(input);

Limits

  • Only statically recognizable /api/ mutations in applicable React modules are reported.

Message IDs

preferServerAction