React & React NativeHooksModerationuseSubmitReport

useSubmitReport

Overview

The useSubmitReport hook allows users to report inappropriate or problematic content. It provides specialized functions to submit reports for comments or entities, with options to specify reasons and additional details.

Usage Example

import { useSubmitReport } from "@replyke/react-js";
 
function ReportButton({ targetId, targetType }: { targetId: string; targetType: "Comment" | "Entity" }) {
  const { submitCommentReport, submitEntityReport } = useSubmitReport();
 
  const handleReport = async () => {
    try {
      if (targetType === "Comment") {
        await submitCommentReport({
          targetId,
          reason: "spam",
          details: "This comment contains spam links."
        });
      } else {
        await submitEntityReport({
          targetId,
          reason: "harassment",
          details: "This entity contains inappropriate content."
        });
      }
 
      console.log("Report submitted successfully.");
    } catch (error) {
      console.error("Failed to submit report:", error.message);
    }
  };
 
  return <button onClick={handleReport}>Report</button>;
}

Parameters & Returns

Parameters

The hook provides two functions with the following parameters:

submitCommentReport

ParameterTypeRequiredDescription
targetIdstringYesThe ID of the comment to report.
reasonReportReasonKeyYesThe reason for reporting the comment.
detailsstringNoAdditional details about the report.

submitEntityReport

ParameterTypeRequiredDescription
targetIdstringYesThe ID of the entity to report.
reasonReportReasonKeyYesThe reason for reporting the entity.
detailsstringNoAdditional details about the report.

Returns

The hook provides the following functions:

FunctionDescription
submitCommentReportSubmits a report for a comment.
submitEntityReportSubmits a report for an entity.