Next.js · Middle · Question 50 of 75

How do you return validation errors to a form from a Server Action?

Explanation

Expected errors (an invalid email) are returned as data: return { errors: { email: 'Invalid address' } }. The form renders them via the useActionState state. Exceptions are reserved for unexpected failures - error.tsx catches them.

Further reading

Problem with a question

Next.js · Middle · question 50

Test yourself

Take the Next.js · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz