Chat Viewer
    Preparing search index...

    Function pinMessagesBy

    • Pins a new message that matches the condition to the top of the viewport and leaves room under it. The content that comes after the message fills the room, so it does not move the list. This is the typical behavior of AI chat apps: the question of the user goes to the top, and the streamed answer grows under it. Other new messages scroll the chat to the bottom when the chat is at the bottom. While a message is pinned, the follow strategies do not scroll the chat.

      Type Parameters

      Parameters

      • shouldPin: (message: M) => boolean

        A function that determines if a received message is pinned. The last one that matches is pinned.

      • OptionalpinOpts: PinOpts

        PinOpts options for the pinned message

      • opts: ScrollToIndexOpts = DEFAULT_SCROLL_OPTS

        ScrollToItemOpts options for the scroll to the other messages

      Returns OnMessagesCallback<M>

      A callback that performs the pin or the scroll action.

      <ChatViewer
      messages={messages}
      renderMessage={renderMessage}
      onNewerMessages={pinMessagesBy(message => message.role === 'user', {
      offset: 12,
      smooth: true,
      })}
      />