useActionState in Next.js

useActionState connects server actions with UI state. It helps handle form submissions, validation, and feedback cleanly.

What is useActionState?

It manages server action results and automatically updates the UI after submission.

How does it work?

const [state, action, pending] =
useActionState(serverAction, initialState);

Example — Form with Server Feedback

Why use it?

Real-World Example

A signup form validates data on the server and instantly shows success or error messages.

Interview Tip

useActionState links server actions with client UI state, simplifying modern form handling.