The unique identifier of the submission for which comments are being fetched.
Optional parameters to control pagination or other filtering options.
The returning object contains:
comments: The list of the comments related to the submission.currentPage: The current page of comments.fetchMore: CommentsFetchMoreMethod - Function to load more comments, appending to the current list.fetched: Boolean indicating whether the comments have been successfully fetched.hasMore: Boolean indicating whether there are more comments to fetch.refresh: CommentsFetchMethod - Function to refresh the current set of comments.usePagination hook to handle paginated
fetching of comments. This allows for loading additional comments when required.withCache utility to cache the API response
for 60 seconds (60,000 ms) to reduce redundant network requests for fetching comments.useEffect hook is used to fetch the comments when
the paramId, scope, or params.page changes.import { useCommentsBySubmission } from 'react-playmakers';
// Using the hook in a component
const SubmissionComments = () => {
const {
comments,
fetchMore,
hasMore,
fetched,
refresh
} = useCommentsBySubmission('SXXXXXXXX', {
page: 1,
limit: 10,
});
if (!fetched) return <div>Loading comments...</div>;
return (
<div>
<h2>Comments</h2>
<button onClick={refresh}>Refresh Comments</button>
<ul>
{comments.map((comment) => (
<li key={comment.id}>
<p><strong>{comment.author}</strong>: {comment.body}</p>
</li>
))}
</ul>
{hasMore && (
<button onClick={() => fetchMore(false)}>Load More</button>
)}
</div>
);
};
Generated using TypeDoc
Custom React hook for managing comments related to a submission.