Client Call

GitHub

Client-only helper that invokes an asynchronous function after rendering.

Installation

bash
pnpm dlx shadcn@latest add @cs/client-call

Usage

tsx
import { ClientCall } from "@/components/cs/client-call";
tsx
<ClientCall
  data={{ event: "page_view" }}
  func={async (data) => {
    await fetch("/api/analytics", {
      method: "POST",
      body: JSON.stringify(data),
    });
  }}
/>

API Reference

ClientCall

Calls an asynchronous function after this client component renders. The component renders no visible output.

Props

NameTypeDefaultDescription
data *T-Data passed to func.
func *(data: T) => Promise<unknown>-Asynchronous callback invoked after rendering.