Trung BìnhNext.js iconNext.js

Error handling trong Server Actions như thế nào?

Server Actions có thể throw errors sẽ được catch bởi nearest error.tsx.

  • Với useFormState/useActionState, return error object thay vì throw: return { error: 'Invalid input' }.
  • Dùng try/catch trong action để handle expected errors (validation, not found) và return user-friendly error states.

Xem toàn bộ Next.js cùng filter theo level & chủ đề con.

Mở danh sách Next.js