How does React Server Actions work in React 19?
Answer
React Server Actions (stable in React 19, via Next.js App Router) are async functions that run on the server and can be called from client components — without needing to write a separate API endpoint. Mark a function with "use server" directive to make it a server action: async function createUser(formData) { "use server"; await db.user.create({ data: { name: formData.get("name") } }); revalidatePath("/users"); }. Invoking from client: pass to a form's action prop: <form action={createUser}><input name="name" /><button>Create</button></form>. The form submission calls the server function without page reload or manual fetch. With useActionState (React 19): const [state, action, isPending] = useActionState(createUser, null); — tracks pending state and the last result. Benefits: no API route boilerplate; progressive enhancement (works without JavaScript for form submissions); mutations are colocated with components; automatic CSRF protection in frameworks; direct database/service access. Security: never trust client-provided data — validate and authorize in the server action body.
Previous
What is the React Activity (Offscreen) API?
Next
What are micro-frontends in the context of React?
More React.js Questions
View all →- Advanced How does React's reconciliation algorithm handle keys?
- Advanced What is the React Fiber architecture in depth?
- Advanced What are React rendering optimizations beyond React.memo?
- Advanced How do you implement an undo/redo system in React?
- Advanced What are React's concurrent features and how do Transitions work?