State Types
State types are used with Next.js server actions and React’suseActionState hook to manage form submission states. These types follow a consistent pattern for handling success and error states.
MessagePrevState
State type for message creation and update operations.Type Definition
Properties
Indicates whether the message operation completed successfully.
true- Message was created/updated successfullyundefined- Operation hasn’t completed or failed
Error message if the operation failed. Contains detailed information about what went wrong.
Usage
Used with thecreateMessage server action in src/lib/actions/message/createMessage.ts:21-24:
PersonPrevState
State type for person creation and update operations.Type Definition
Properties
Indicates whether the person operation completed successfully.
true- Person was created/updated successfullyundefined- Operation hasn’t completed or failed
Error message if the operation failed.
Usage
Used with thecreatePerson server action in src/lib/actions/people/createPerson.ts:18-21:
RescheduleState
State type for the message rescheduling operation.Type Definition
Properties
Indicates whether the reschedule operation completed successfully.
Unlike other state types,
success is required (not optional) in RescheduleState.true- Messages were rescheduled successfullyfalse- Reschedule operation failed
Error message if the operation failed. Only present when
success is false.Possible values:- Error message from caught exception
"Unknown error"- Fallback for non-Error exceptions
Key Difference
Important:
RescheduleState.success is required, while MessagePrevState.success and PersonPrevState.success are optional.This means a RescheduleState always has an explicit success value (true or false), whereas other state types use undefined to indicate pending/initial state.Usage
Used with thereschedule server action in src/lib/actions/reschedule/reschedule.ts:10:
State Pattern Overview
All state types follow a consistent pattern for error handling in Next.js server actions:Success/Error Pattern
- Initial State: Empty object or
{ success: false } - Success: Returns
{ success: true } - Validation Error: Returns
{ error: "validation message" } - API Error: Returns
{ error: "Backend Error: ..." } - Exception: Returns
{ error: error.message }