Action result
GitHubTyped result contract for server actions, including HTTP status, message, redirect, payload data, and toast feedback.
Installation
bash
pnpm dlx shadcn@latest add @cs/action-resultUsage
tsx
import { actionResult, type ActionResult } from "@/lib/cs/action-result";tsx
const result: ActionResult<{ id: string }> = actionResult({
status: 200,
message: "Your session is about to expire",
toast: "warning",
})API Reference
actionResult
Creates a normalized result object for server actions.
Props
| Name | Type | Default | Description |
|---|---|---|---|
| data | T | - | Optional typed action payload. |
| message | string | - | Optional message for UI feedback. |
| redirect | string | - | Optional redirect destination after a successful action. |
| status * | HttpStatus | - | - |
| toast | "info" | "warning" | "error" | "success" | - | Optional toast variant that overrides the default success or error feedback. |