Skip to main content

Overview

Returns a function to submit a content report on behalf of the authenticated user. Pass type: "comment" or type: "entity" when calling the hook — the returned function is pre-configured for that target type. If the same target has already been reported, the user’s report is appended to the existing report record (the system deduplicates reports per-user). Reporting the same target twice has no additional effect.
Requires an authenticated user.

Usage Example

import { useCreateReport } from "@replyke/react-js";

function ReportEntityButton({ entityId }: { entityId: string }) {
  const createEntityReport = useCreateReport({ type: "entity" });

  const handleReport = async () => {
    await createEntityReport({
      targetId: entityId,
      reason: "spam",
    });
    alert("Report submitted.");
  };

  return <button onClick={handleReport}>Report</button>;
}

Parameters

type
"comment" | "entity"
required
The target type this hook instance will report against. Determines the shape of the returned function.

Returned Function

The hook returns either createCommentReport or createEntityReport depending on the type argument. Both functions accept the same parameters:
targetId
string
required
The ID of the comment or entity being reported.
reason
ReportReasonKey
required
The reason for the report. Must be one of the following keys:
KeyLabel
spamIt’s spam
inappropriateContentContains inappropriate content
harassmentIt’s harassment or bullying
misinformationSpreads false information
hateSpeechContains hate speech or symbols
violencePromotes violence or dangerous behavior
illegalActivityPromotes illegal activity
selfHarmPromotes self-harm or suicide
otherOther
details
string
Optional free-text elaboration on the reason.

Returns

The returned function returns Promise<void>. It resolves when the report is accepted (whether created or appended to an existing one).

Notes

  • If the target has already been reported by this user, the server returns 200 with code report/already-reported without error. The hook function resolves normally in this case.
  • Reports are scoped to the space the content belongs to, enabling space moderators to action them. See useFetchModeratedReports.