Const
Type of messages, which must extend IdentifiableMessage. It can be any type that has an id
property for unique identifying messages.
ChatViewerProps properties for the component and ref
that will expose ChatViewerHandle's methods.
Optional
alignment?: ChatAlignmentAlignment of the chat list. Determines whether new messages appear at the top or bottom.
Optional
className?: stringClass name for the root element of the chat viewer.
Optional
historyEndOffset?: numberOffset in pixels from the end of the history at which to trigger onHistoryEndReached.
Optional
keepMountedIds?: MessageId<M>[]MessageIds of messages to keep mounted even when out of view.
Optional
keepMountedIndexes?: number[]Indexes of messages to keep mounted even when out of view. This allows you to preserve the state of messages that are not currently visible.
The array of messages to display in the chat viewer.
Optional
onAtBottom?: ChatCallback<M>Callback fired when the viewport reaches the bottom of the message list.
ChatViewerHandle instance. Allows you to control the chat viewer.
Optional
onAtTop?: ChatCallback<M>Callback fired when the viewport reaches the top of the message list.
ChatViewerHandle instance. Allows you to control the chat viewer.
Optional
onHistoryEndReached?: ChatCallback<M>Callback fired when the user scrolls to the end of the history (top or bottom, depending on alignment).
ChatViewerHandle instance. Allows you to control the chat viewer.
Optional
onKeyDown?: KeyboardEventHandlerCallback fired on key down events in the scrollable container.
Optional
onNewerMessages?: OnMessagesCallback<M>Callback fired when newer messages are requested (e.g., user scrolls to the bottom).
You might want to use this callback with utility functions like followEveryMessage, followMessagesAtBottom, or followMessagesBy to automatically scroll to automatically follow new messages.
<ChatViewer
messages={messages}
renderMessage={renderMessage}
onNewerMessages={followMessagesAtBottom()}
/>
ChatViewerHandle instance. Allows you to control the chat viewer.
followMessagesAtBottom - scrolls to the bottom when viewport is at the bottom of the history.
Optional
onOlderMessages?: OnMessagesCallback<M>Callback fired when older messages are requested (e.g., user scrolls to the top).
ChatViewerHandle instance. Allows you to control the chat viewer.
Optional
onPrefixDisplay?: OnAffixCallback<M>Callback fired when the prefix node is displayed in the viewport.
ChatViewerHandle instance. Allows you to control the chat viewer.
Optional
onScroll?: (offset: number) => voidCallback fired on scroll with the current scroll offset.
Optional
onScrollEnd?: () => voidCallback fired when scrolling ends.
Optional
onSuffixDisplay?: OnAffixCallback<M>Callback fired when the suffix node is displayed in the viewport.
ChatViewerHandle instance. Allows you to control the chat viewer.
followSuffixAtBottom - scrolls to the bottom when viewport when suffix is displayed at the bottom of the history.
Optional
onWheel?: WheelEventHandlerCallback fired on wheel events in the scrollable container.
Optional
overscan?: numberNumber of extra items to render beyond the visible area (for virtualization performance).
Passed to Virtua's overscan
prop.
Optional
prefix?: ReactNodeReact node to render before the message list (e.g., a header or history loader). It can be conditionally displayed. When changed, it will trigger a onPrefixDisplay callback.
A React ref created by useRef
hook. It will expose ChatViewerHandle instance for imperative control over the chat viewer.
Function to render a message.
Optional
scrollerClassName?: stringClass name for the scrollable container.
Optional
scrollerStyle?: CSSPropertiesStyle for the scrollable container.
Optional
ssrCount?: numberNumber of items to render on the server for SSR. Passed to Virtua's ssrCount
prop.
Optional
style?: CSSPropertiesStyle for the root element of the chat viewer.
Optional
suffix?: ReactNodeReact node to render after the message list (e.g., a footer or typing indicator). It can be conditionally displayed. When changed, it will trigger a onSuffixDisplay callback.
ChatViewer component that implements a virtualized chat viewer. It supports features like prefix and suffix rendering, scrolling to specific messages, and tracking seen messages.