Sanity App SDK
    Preparing search index...
    • Function

      Reads a document's comments grouped into threads.

      A thread is one comment plus its replies. Its status and fieldPath come from the first comment, so filtering by either selects whole threads rather than stray replies.

      Unlike the Studio, every thread is returned. The Studio hides threads whose field has left the schema or is hidden by a conditional, which it can do because it has the schema to check against. Inspect fieldPath yourself if your app needs to do the same.

      Parameters

      • options: WithResourceNameSupport<CommentsOptions>

        The document to read, optionally narrowed by fieldPath or status

      Returns UseCommentThreadsResult

      The matching threads, and whether a switch is in flight

      function Threads({documentId}: {documentId: string}) {
      const {threads} = useCommentThreads({
      documentId,
      documentType: 'article',
      status: 'open',
      })

      return (
      <ul>
      {threads.map((thread) => (
      <li key={thread.threadId}>
      {thread.fieldPath || 'Document'}{thread.commentsCount} comments
      </li>
      ))}
      </ul>
      )
      }