Action response
GitHubCreates JSON HTTP responses from typed action result values.
Installation
bash
pnpm dlx shadcn@latest add @cs/action-responseUsage
tsx
import { actionResponse } from "@/lib/cs/action-response"tsx
const response = actionResponse({
status: 200,
message: "Your session is about to expire",
toast: "warning",
})API Reference
actionResponse
Creates a normalized JSON response for server actions.
tsx
actionResponse(redirect: string, message?: string): NextResponse<ActionResult>
actionResponse(status: HttpStatus, message?: string, data?: T): NextResponse<ActionResult<T>>
actionResponse(result: ActionResult<T>): NextResponse<ActionResult<T>>
actionResponse(param1: string | HttpStatus | ActionResult<T>, param2?: string, param3?: T): NextResponse<ActionResult<T>>Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| param1 * | string | HttpStatus | ActionResult<T> | - | - |
| param2 | string | - | - |
| param3 | T | - | - |