Metadata

In Comments, each thread and comment can be given custom metadata. This is helpful for integrating Comments into various applications, for example it can be used to store:

  • The priority, status, or category of a thread.
  • Coordinates or timestamps related to the thread.
  • Quoted text in a text editor.
  • Tags, context, or flags on a comment.
  • External IDs like Slack message IDs on comments to build two-way integrations.

Valid metadata

You can store any string, boolean, or number in metadata, for example:

Setting a property to null will remove it.

You can store up to 50 metadata properties per thread or comment, and each property can be 4000 characters long.

Setting metadata

Metadata can be set using the default components, React hooks, or by editing threads and comments using the REST APIs. But before making any changes, it’s recommended to set your metadata types in your config file.

liveblocks.config.ts

Learn more about typing your data.

Composer component

The <Composer /> component is used to create threads and comments, and by default it’ll create a new thread, with optional metadata, when its form is submitted.

Composer

When using it to create a thread, you can pass custom metadata, which will be attached to the thread.

When using it to reply to a thread, you can also pass custom metadata, which will be attached to the comment.

Mutation hooks

Several mutation hooks allow you to edit thread and comment metadata: useEditThreadMetadata, useEditCommentMetadata, and useCreateThread. Here’s one way to create a button that sets the pinned metadata property to true on a thread.

Here’s an example of editing comment metadata:

REST APIs

It’s possible to modify metadata from our REST APIs using the @liveblocks/node package. Here’s an example using liveblocks.editThreadMetadata for threads.

And here’s an example using liveblocks.editCommentMetadata for comments.

The same result can also be achieved directly through our edit thread metadata REST API.

And our edit comment metadata REST API.