The identifier of the owner whose comments are to be fetched.
Additional parameters for filtering or customizing the comments fetch operation.
The returning object contains:
comments
: The list of the comments related to a specific owner.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
or refreshing the first page.withCache
utility is employed to cache API responses for
120 seconds (120,000 ms) to minimize redundant network requests.useEffect
hook is used to initiate the data fetch whenever
the id
or params
(such as page) change.import { useCommentsByOwner } from 'react-playmakers';
// Using the hook in a component
const OwnerComments = () => {
const {
comments,
fetchMore,
refresh,
hasMore,
fetched,
currentPage
} = useCommentsByOwner('XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX',
{ page: 1, limit: 10 });
// Fetch initial comments on mount
useEffect(() => {
refresh();
}, [refresh]);
if (!fetched) return <p>Loading comments...</p>;
return (
<div>
<h2>Owner Comments</h2>
{comments.length > 0 ? (
<>
<ul>
{comments.map(comment => (
<li key={comment.id}>
<p>{comment.body}</p>
<small>State: {comment.state}</small>
</li>
))}
</ul>
{hasMore && <button onClick={() => fetchMore(false)}>Load More</button>}
</>
) : (
<p>No comments available for this owner.</p>
)}
{currentPage && <p>Current Page: {currentPage}</p>}
</div>
);
};
Generated using TypeDoc
Custom React hook for managing comments associated with a specific owner.