> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sublay.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Fetch comments by user

> Fetch a page of a user's comment history

export const SpaceReputationParams = ({variant = "context", field = "path"}) => {
  const isUser = variant === "user";
  return <>
      <ParamField {...{
    [field]: "spaceReputation",
    type: "object"
  }}>
        Opt-in. Adds a <code>spaceReputation</code> number to each returned user,
        scoped to a single space. Requires the <code>reputation</code> bundle.
        The <code>reputation</code> total is always present regardless;{" "}
        <code>spaceReputation</code> is purely additive and only appears when you
        pass this object. <strong>This object is the primary form</strong> — it
        replaces the deprecated flat props below. See the{" "}
        <a href="/v8/data-models/reputation">Reputation data model</a> for the
        full contract.

        <Expandable title="spaceReputation">
          {isUser ? <ParamField name="spaceId" type="string | &quot;none&quot;" required>
              Which bucket to read. A space <strong><code>&lt;uuid&gt;</code></strong> reads that
              space's bucket; <strong><code>"none"</code></strong> reads the
              project-general (space-less) bucket.{" "}
              <strong><code>"context"</code> is rejected (400)</strong> on this
              endpoint — there is no space context to derive. The empty string
              and the legacy <code>general</code> / <code>null</code> aliases are
              also rejected. Missing buckets read as <code>0</code>.
            </ParamField> : <ParamField name="spaceId" type="string | &quot;none&quot; | &quot;context&quot;" required>
              Which bucket to read. One of: a space <strong><code>&lt;uuid&gt;</code></strong>{" "}
              (that space's bucket), <strong><code>"none"</code></strong> (the
              project-general, space-less bucket), or{" "}
              <strong><code>"context"</code></strong> (the space derived from the
              request context — resolved per-row on lists, or the single space on
              member/team/conversation surfaces). The empty string and the legacy{" "}
              <code>general</code> / <code>null</code> aliases are rejected (400).
              Missing buckets read as <code>0</code>.
            </ParamField>}
          <ParamField name="includeDescendants" type="boolean">
            Only honored when <code>spaceId</code> is an explicit space <code>&lt;uuid&gt;</code>.
            When <code>true</code>, <code>spaceReputation</code> is the{" "}
            <strong>subtree sum</strong> — the named space plus all of its
            descendant spaces (the root space's own bucket included). Ignored for{" "}
            <code>"none"</code>; not allowed with <code>"context"</code>.
          </ParamField>
        </Expandable>
      </ParamField>

      {isUser ? <ParamField {...{
    [field]: "spaceReputationId",
    type: "string",
    deprecated: true
  }}>
          <strong>Deprecated</strong> — use the <code>spaceReputation</code>{" "}
          object instead. The flat form of <code>spaceReputation.spaceId</code>.
          Still accepted (the object wins if both are passed); removal is a later
          major version. Accepts a space <code>&lt;uuid&gt;</code> or <code>"none"</code> only —{" "}
          <code>"context"</code> is rejected (400) on this endpoint.
        </ParamField> : <ParamField {...{
    [field]: "spaceReputationId",
    type: "string",
    deprecated: true
  }}>
          <strong>Deprecated</strong> — use the <code>spaceReputation</code>{" "}
          object instead. The flat form of <code>spaceReputation.spaceId</code>.
          Still accepted (the object wins if both are passed); removal is a later
          major version. Accepts a space <code>&lt;uuid&gt;</code>, <code>"none"</code>, or{" "}
          <code>"context"</code>.
        </ParamField>}

      <ParamField {...{
    [field]: "spaceReputationDescendants",
    type: "boolean",
    deprecated: true
  }}>
        <strong>Deprecated</strong> — use{" "}
        <code>spaceReputation.includeDescendants</code> instead. The flat form,
        only honored alongside an explicit <code>spaceReputationId</code> <code>&lt;uuid&gt;</code>.
      </ParamField>
    </>;
};

## Overview

`useFetchCommentsByUserId` returns a function that fetches one page of a user's comments ([`GET /users/:userId/comments`](/v8/api-reference/users/fetch-comments-by-user-id)) — top-level comments and replies alike, across entities, cursor-paginated. For a stateful list with "load more", use [`useFetchCommentsByUserIdWrapper`](/v8/hooks/comments/use-fetch-comments-by-user-id-wrapper).

What the list contains:

* Deleted comments are left out. Moderator-removed comments are left out of other people's history, and included in full (marked `moderationStatus: "removed"`) in the signed-in user's own.
* Comments by users the signed-in user is block-edged with are left out by default (`blockedFilter`).
* Comments on an entity whose author has blocked the signed-in user are left out — except their own, which stay visible so they can be found and deleted. On those, `entity` and `parentComment` are `null` when requested, and replying, reacting and editing are refused.
* `include` never changes which comments are returned. `entity` is `null` when the entity isn't available to the signed-in user (for example, removed by a moderator) — the comment is still returned, and `null` doesn't say why.

## Usage Example

```tsx theme={null}
import { useFetchCommentsByUserId } from "@sublay/react-js";

function LatestComments({ userId }: { userId: string }) {
  const fetchCommentsByUserId = useFetchCommentsByUserId();

  const load = async () => {
    const { data, pagination } = await fetchCommentsByUserId({
      userId,
      limit: 5,
      include: ["entity"],
    });
    console.log(data, pagination.nextCursor);
  };

  return <button onClick={load}>Load</button>;
}
```

## Parameters

<ParamField path="userId" type="string" required>
  The user whose comments to fetch.
</ParamField>

<ParamField path="entityId" type="string | null">
  Only comments on this entity.
</ParamField>

<ParamField path="sourceId" type="string | null">
  Only comments on entities with this `sourceId`.
</ParamField>

<ParamField path="blockedFilter" type="&#x22;exclude&#x22; | &#x22;include-outbound-blocked&#x22; | null">
  Server default `"exclude"`: comments by block-edged users are left out. `"include-outbound-blocked"` re-includes comments by users the signed-in user blocked, marked `isAuthorBlocked: true`.
</ParamField>

<ParamField path="limit" type="number">
  Comments per page. Server default `10`, max `100`.
</ParamField>

<ParamField path="cursor" type="string | null">
  `pagination.nextCursor` from the previous response. Omit for the first page. Send the same sort as the request that returned it.
</ParamField>

<ParamField path="sortBy" type="CommentsSortByOptions">
  `"createdAt"`, `"top"` (raw count of `sortByReaction`) or `"controversial"`. Server default `"createdAt"`.
</ParamField>

<ParamField path="sortDir" type="&#x22;asc&#x22; | &#x22;desc&#x22;">
  Applies to every sort. Server default `"desc"`.
</ParamField>

<ParamField path="sortByReaction" type="ReactionType">
  With `sortBy: "top"` only. Server default `"upvote"`.
</ParamField>

<ParamField path="include" type="CommentIncludeParam">
  Related data to populate: `"user"`, `"entity"`, `"space"`, `"parent"`, `"grants"`.
</ParamField>

<SpaceReputationParams variant="context" field="path" />

## Returns

A `Promise<CursorPaginatedResponse<Comment>>`:

<ResponseField name="data" type="Comment[]">
  The user's comments for this page. See [Comment](/v8/data-models/comment).
</ResponseField>

<ResponseField name="pagination.nextCursor" type="string | null">
  Pass as `cursor` to get the next page. `null` when there's nothing more.
</ResponseField>

<ResponseField name="pagination.hasMore" type="boolean">
  Whether more comments exist after this page.
</ResponseField>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.