Action result

GitHub

Typed result contract for server actions, including HTTP status, message, redirect, payload data, and toast feedback.

Installation

bash
pnpm dlx shadcn@latest add @cs/action-result

Usage

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

NameTypeDefaultDescription
dataT-Optional typed action payload.
messagestring-Optional message for UI feedback.
redirectstring-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.

Dependencies