Skip to main content

Overview

useFetchManyComments returns a function that fetches a paginated list of comments. This is the underlying fetch function used by useEntityComments and useReplies. Use it directly when you need a custom comment list outside of those hooks.

Usage Example

import { useFetchManyComments } from "@replyke/react-js";
import { useState, useEffect } from "react";

function UserComments({ userId }: { userId: string }) {
  const fetchComments = useFetchManyComments();
  const [comments, setComments] = useState([]);

  useEffect(() => {
    fetchComments({ userId, page: 1, limit: 10 }).then((res) =>
      setComments(res.data)
    );
  }, [userId]);

  return (
    <ul>
      {comments.map((c) => <li key={c.id}>{c.content}</li>)}
    </ul>
  );
}

Parameters

page
number
required
Page number (1-indexed). Must be greater than 0.
entityId
string
Filter to comments on a specific entity.
userId
string
Filter to comments by a specific user.
parentId
string
Filter to replies of a specific parent comment.
sortBy
string
Sort order: "top", "new", or "controversial".
limit
number
Results per page. Must be greater than 0.
sourceId
string
Filter to comments within a specific source.
include
string | string[]
Populate related data. Accepted values: "user", "entity", "space", "parent".

Returns

data
Comment[]
Comments for the current page.
pagination.hasMore
boolean
Whether there are more pages to load.