React & React NativeHooksModerationuseCreateReport

useCreateReport

Overview

The useCreateReport hook allows users to report inappropriate or problematic content. It requires a type parameter to specify whether you’re reporting comments or entities, and returns a specialized function for that type.

Usage Example

import { useCreateReport } from "@replyke/react-js";
 
function CommentReportButton({ commentId }: { commentId: string }) {
  const createCommentReport = useCreateReport({ type: "comment" });
 
  const handleReport = async () => {
    try {
      await createCommentReport({
        targetId: commentId,
        reason: "spam",
        details: "This comment contains spam links."
      });
 
      console.log("Comment report created successfully.");
    } catch (error) {
      console.error("Failed to create report:", error.message);
    }
  };
 
  return <button onClick={handleReport}>Report Comment</button>;
}
 
function EntityReportButton({ entityId }: { entityId: string }) {
  const createEntityReport = useCreateReport({ type: "entity" });
 
  const handleReport = async () => {
    try {
      await createEntityReport({
        targetId: entityId,
        reason: "harassment",
        details: "This entity contains inappropriate content."
      });
 
      console.log("Entity report created successfully.");
    } catch (error) {
      console.error("Failed to create report:", error.message);
    }
  };
 
  return <button onClick={handleReport}>Report Entity</button>;
}

Parameters & Returns

Hook Parameters

The hook accepts an object with the following field:

ParameterTypeRequiredDescription
type"comment" | "entity"YesSpecifies whether to report comments or entities.

Returns

The hook returns a single function based on the type specified:

  • For type: "comment": Returns createCommentReport function
  • For type: "entity": Returns createEntityReport function

Function Parameters

Both returned functions accept the same parameters:

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