Skip to main content
The @kansato/whistle-react package provides a React SDK for embedding Whistle report forms with server-side reporter validation. Reports are proxied through your Next.js server, preventing client-side spoofing of reporter information.

Install

Quick setup

1. Create the route handler

Create app/api/whistle/report/route.ts:
No file copying. No global variables.

2. Configure environment variables

Never expose WHISTLE_API_KEY to the client. Use secret keys (sk_live_) server-side only.

3. Wrap with WhistleProvider

4. Use the component or hook

Component (recommended):
Hook:

Components

WhistleProvider

ReportDialog

Ready-to-use report dialog component with secure submission.

Hooks

Submits reports through your platform’s server. Reporter information is attached server-side automatically.

useReportSubmission (legacy)

Direct API submission using publishable keys. Less secure — only use if you cannot implement a server-side proxy.

useWhistle()

Low-level hook for opening the hosted report dialog programmatically.

Controlled submission

By default, the report form iframe POSTs directly to your route handler. Pass an onSubmit prop to intercept form data and submit it yourself (server action, custom fetch, etc.).
Available on ReportDialog, ReportForm, and ReportFrame. Its presence enables controlled mode — no extra config needed.

Direct vs controlled

Use controlled mode when you need server actions, custom endpoints, pre-processing, multi-step confirmation flows, or offline queuing.

onSubmit data shape

Handler configuration

Options

getReporter — Auth provider examples

Pass a getReporter function to attach user identity server-side. The client cannot spoof this. Type signature:

Anonymous reporting

Omit getReporter. Reports are submitted with an anonymous reporter derived from request IP:

getReportMetadata — Custom metadata

Attach platform-specific context to every report:
Default metadata includes userAgent, ip, and timestamp when omitted.

Edge runtime

Add export const runtime = "edge" to your route file. The handler uses only Web APIs and is fully edge-compatible. Omit for Node.js runtime (default).

Types

IngestSubject

ReportTarget

ReportReasonInput

API keys

Create keys in Settings > Developer > API Keys. Never expose secret keys to the client.

Migration from direct API

If you were using useReportSubmission with direct API calls: Before:
After:
  • Need keys and auth details? See Developer access.
  • Need server-side ingestion? See Node SDK.
  • Need a non-React frontend? Use the hosted iframe snippet from Settings > Developer.