Stream Chat React SDK

repository·master·Indexed 21 days ago

https://github.com/getstream/stream-chat-react

The official React SDK for Stream Chat, providing a comprehensive component library for building messaging, team collaboration, and livestream chat interfaces. It features a provider/consumer pattern via WithComponents for UI overrides, CSS layer-based theming, and support for internationalization. The SDK includes a migration path from v13 to v14, introducing hooks to replace HOCs, a new MessageComposer system, and updated stylesheet import paths.

Tokens
49.8K
Snippets
122
Records
348
Agent score
73%

What's inside stream-chat-react

  1. Jump to message behavior via jumpToMessage()

    master

    The jumpToMessage(...) functionality (used for quoted-message jumps and other navigation) is designed to be render-driven to prevent visual glitches.

    Key behaviors include:

    • No Intermediate Scrolling: The list does not scroll the current (old) page before the target page is rendered.
    • Direct Navigation: The list scrolls directly toward the target message.
    • Directional Awareness: The animation uses the appropriate entry edge depending on whether the jump is to an older or newer page.
  2. Customize Gallery UI

    master

    You can provide a custom UI for the Gallery component by passing a component to the GalleryUI prop. The custom component can then use the useGalleryContext hook to access navigation and state.

    By default, the GalleryUI component handles:

    • Rendering images via BaseImage or videos via a <video> element.
    • Keyboard navigation (left/right arrow keys).
    • A position indicator (e.g., "3 / 10").
    • Loading and error states.
    import { Gallery, GalleryUI } from './components/Gallery';
    
    // Using the default UI
    <Gallery items={items} GalleryUI={GalleryUI} />
  3. Handle ChatView thread placeholder behavior

    master
    In v14, ChatView.ThreadAdapter renders an EmptyStateIndicator with the message "Select a thread to continue the conversation" when a thread is ready but none is selected. If you prefer the legacy behavior of a blank state, you can either override the EmptyStateIndicator to return null or manually wire the ThreadProvider.
  4. Manage dialogs and modals with GlobalModal and DialogManagerProvider

    master

    The SDK provides a robust system for managing overlays:

    • GlobalModal: The public surface for rendering top-level modals.
    • DialogManagerProvider: A provider that manages dialog lifecycles. It includes a closeOnClickOutside prop to control whether clicking the backdrop closes the dialog.
    • ContextMenu: Configurable via a dedicated transition configuration surface.
    • WithComponents: The standard pattern for overriding modal components.
  5. Manage Dialogs and Modals with GlobalModal

    master
    The legacy Modal component is no longer exported in v14. Instead, use the GlobalModal component. Note that GlobalModal does not render the legacy .str-chat__modal__inner wrapper. Dialog management should be handled via the current WithComponents and dialog primitives provided by the SDK.
  6. Understand MessageComposer layout during slash commands

    master

    When a slash command is active in MessageInputFlat, the UI undergoes specific layout changes:

    • The class str-chat__message-composer--command-active is applied.
    • The attachment selector slot is hidden.
    • AdditionalMessageComposerActions are collapsed.
    • The audio-recording button in MessageComposerActions is hidden.
  7. How component reusability works with WithComponents

    master

    The library uses a provider/consumer pattern to separate business logic from UI rendering. For components with significant logic, you can swap out the UI layer without affecting the underlying functionality by using the WithComponents component and its overrides prop.

    This allows you to pass a custom UI component (e.g., CustomMessageUI) to replace a standard component (e.g., MessageUI) within a specific part of the chat interface.

    <Channel>
      <Window>
        <ChannelHeader />
        <WithComponents overrides={{ MessageUI: CustomMessageUI }}>
          <MessageList />
        </WithComponents>
        <MessageComposer />
      </Window>
      <Thread />
    </Channel>
  8. Use HeaderStartContent slot for sidebar toggles

    master

    The ChannelHeader component does not manage sidebar visibility or include a built-in MenuIcon or sidebarCollapsed prop. Instead, the sidebar toggle is provided externally via the HeaderStartContent slot within the ComponentContext.

    Applications should provide their own toggle implementation via WithComponents to control sidebar state, as the SDK does not own the sidebar's collapsed/expanded state.

  9. Configure notification tags and panel resolution

    master

    Notifications can now include an optional tags?: string[] array in their model/options.

    Panel Resolution Logic:

    1. The system first prioritizes target:<panel> tags assigned internally by stream-chat-react.
    2. If no matching target tags are found, it falls back to the origin.context.panel value for backward compatibility.

    This allows for more granular control over where notifications appear by using specific tags.

  10. Common Integration Scenarios

    master

    Depending on your project structure, use one of the following patterns:

    • New React App (Vite/CRA): Follow the standard Quick Start pattern by initializing the client at the top level of your application.
    • Add Chat to Existing App: Integrate the <Chat> provider and client initialization into your existing component tree, ensuring the client is created only once.
    • Custom Styling: Apply themes or custom CSS to override the default stream-chat-react/dist/css/v2/index.css styles.
    • Custom Components: Replace default UI elements (like MessageList or MessageInput) with your own components by passing them as props or using the provided context.