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:
Parameter | Type | Required | Description |
---|---|---|---|
type | "comment" | "entity" | Yes | Specifies whether to report comments or entities. |
Returns
The hook returns a single function based on the type specified:
- For
type: "comment"
: ReturnscreateCommentReport
function - For
type: "entity"
: ReturnscreateEntityReport
function
Function Parameters
Both returned functions accept the same parameters:
Parameter | Type | Required | Description |
---|---|---|---|
targetId | string | Yes | The ID of the comment or entity to report. |
reason | ReportReasonKey | Yes | The reason for reporting the content. |
details | string | No | Additional details about the report. |