@ably/chat - v0.12.0
    Preparing search index...

    Function ChatClientProvider

    • Returns a React component that provides a ChatClient in a React context to the component subtree. Updates the context value when the client prop changes.

      Important: The client should be memoized to prevent unnecessary context updates. Ideally, the ChatClient and its underlying Ably.Realtime client should be created outside of React components to avoid duplicate connections.

      Parameters

      Returns Element

      A React element that provides the chat client context to its children.

      import * as Ably from 'ably';
      import { ChatClient } from '@ably/chat';
      import { ChatClientProvider } from '@ably/chat/react';

      // Create client outside React to avoid recreating on re-renders
      const realtime = new Ably.Realtime({ key: 'your-api-key', clientId: 'user-123' });
      const chatClient = new ChatClient(realtime);

      const App = () => {
      return (
      <ChatClientProvider client={chatClient}>
      <MyChatApp />
      </ChatClientProvider>
      );
      };