useCreateReport
Overview
The useCreateReport
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 { useCreateReport } from "@replyke/react-js";
function ReportButton({ targetId, targetType }: { targetId: string; targetType: "Comment" | "Entity" }) {
const { createCommentReport, createEntityReport } = useCreateReport();
const handleReport = async () => {
try {
if (targetType === "Comment") {
await createCommentReport({
targetId,
reason: "spam",
details: "This comment contains spam links."
});
} else {
await createEntityReport({
targetId,
reason: "harassment",
details: "This entity contains inappropriate content."
});
}
console.log("Report created successfully.");
} catch (error) {
console.error("Failed to create report:", error.message);
}
};
return <button onClick={handleReport}>Report</button>;
}
Parameters & Returns
Parameters
The hook provides two functions with the following parameters:
createCommentReport
Parameter | Type | Required | Description |
---|---|---|---|
targetId | string | Yes | The ID of the comment to report. |
reason | ReportReasonKey | Yes | The reason for reporting the comment. |
details | string | No | Additional details about the report. |
createEntityReport
Parameter | Type | Required | Description |
---|---|---|---|
targetId | string | Yes | The ID of the entity to report. |
reason | ReportReasonKey | Yes | The reason for reporting the entity. |
details | string | No | Additional details about the report. |
Returns
The hook provides the following functions:
Function | Description |
---|---|
submitCommentReport | Submits a report for a comment. |
submitEntityReport | Submits a report for an entity. |