> ## 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.

# Create comment

> Create a new comment or reply on an entity

## Overview

`useCreateComment` returns a function that creates a new comment. Use it directly for low-level comment creation. Inside a `CommentSectionProvider`, prefer `createComment` from `useCommentSection` — it adds optimistic UI and manages the comment tree automatically.

> [!NOTE]
>
> Requires an authenticated user.

## Usage Example

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

function PostComment({ entityId }: { entityId: string }) {
  const createComment = useCreateComment();

  const handleSubmit = async (text: string) => {
    const comment = await createComment({
      entityId,
      content: text,
    });
    console.log("Created:", comment.id);
  };

  return <button onClick={() => handleSubmit("Hello!")}>Comment</button>;
}
```

## Parameters

**entityId** `string` *required*

The entity to comment on.

**content** `string`

Text content of the comment. Required if `gif` is not provided.

**gif** `GifData`

GIF attachment. Required if `content` is not provided.

**parentCommentId** `string`

ID of the parent comment for replies.

**foreignId** `string`

Your own ID to associate with this comment.

**referencedCommentId** `string`

ID of a comment being referenced/quoted in this comment.

**mentions** `Mention[]`

Users or spaces mentioned in the comment content.

**attachments** `Record\<string, any\>[]`

Arbitrary attachment metadata.

**metadata** `Record\<string, any\>`

Arbitrary project-specific data.

## Returns

**Comment** `Comment`

The newly created comment. See [Comment data model](https://docs.sublay.io/v7/data-models/comment.md).


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