Sanity App SDK
    Preparing search index...
    • Function

      Reads a document's comments and keeps them up to date.

      Comments are shared with the Studio: they live in the project's comments dataset, so a thread started here shows up there and the other way round. The list is flat, replies included; reach for useCommentThreads to read it grouped.

      Suspends until the comments have loaded. Switching document or filter is a transition, so the previous list stays on screen and isPending goes true rather than the component suspending again.

      Parameters

      • options: WithResourceNameSupport<CommentsOptions>

        The document to read, optionally narrowed by fieldPath or status

      Returns UseCommentsResult

      The matching comments, and whether a switch is in flight

      function TitleCommentCount({documentId}: {documentId: string}) {
      const {comments} = useComments({
      documentId,
      documentType: 'article',
      fieldPath: 'title',
      status: 'open',
      })

      return <span>{comments.length}</span>
      }