Optional
commentId: stringThe unique identifier of the comment to manage. If provided, it will attempt to fetch the comment upon hook initialization.
The returning object contains:
comment
: The current comment object.fetched
: Boolean indicating whether the comment data has been fetched successfully.refresh
: CommentFetchMethod - Function to refresh the comment data by fetching it again from the API.createApproveComment
: CommentCreateStudioMethod - Function to create a comment in
an approved state (studio accepted).createComment
: CommentCreateMethod - Function to create a new comment.createRejectComment
: CommentCreateStudioMethod - Function to create a comment in
a rejected state (studio rejected).deleteComment
: CommentDeleteMethod - Function to delete the current comment.editComment
: CommentEditMethod - Function to edit the body of the current comment.hideComment
: CommentHideMethod - Function to hide the current comment.useEffect
hook automatically fetches the comment data when the commentId
changes.import { useComment } from 'react-playmakers';
// Using the hook in a component
const CommentComponent = () => {
const {
comment,
fetched,
refresh,
createComment,
editComment,
deleteComment,
hideComment,
createApproveComment,
createRejectComment,
} = useComment('cXXXXXXXX');
// Fetch the comment on demand
useEffect(() => {
if (!fetched) {
refresh();
}
}, [fetched, refresh]);
// Handle creating a new comment
const handleCreate = async () => {
const newComment = await createComment('SXXXXXXXX', 'New comment body');
console.log('Created comment:', newComment);
};
// Handle editing the current comment
const handleEdit = async () => {
if (comment) {
const updatedComment = await editComment('Updated comment body');
console.log('Updated comment:', updatedComment);
}
};
// Handle deleting the current comment
const handleDelete = async () => {
if (comment) {
await deleteComment();
console.log('Comment deleted');
}
};
return (
<div>
<h3>Comment Details</h3>
<p>{comment?.body || 'No comment available'}</p>
<button onClick={handleCreate}>Create Comment</button>
<button onClick={handleEdit}>Edit Comment</button>
<button onClick={handleDelete}>Delete Comment</button>
</div>
);
};
Generated using TypeDoc
Custom React hook for managing a comment.