import { default as React, ReactNode } from 'react'; import { RoomOptions } from '../../core/room-options.js'; /** * Props for the {@link ChatRoomProvider} component. */ export interface ChatRoomProviderProps { /** The name of the room. */ name: string; /** * Overriding options to use when creating the room. See {@link RoomOptions} for details. * * **Important**: * - The `options` should be memoized to prevent unnecessary room recreations. Passing a new object reference * on each render will cause the room to be released and recreated. * - Provided options are merged with the default options, so you only need to specify the options you want to change. * - Room options cannot be changed after the room is created. Different options * for the same room name will result in an error. * @example * ```tsx * const MyRoomComponent = () => { * const [typing, setTyping] = useState(true); * * const roomOptions = useMemo(() => ({ * typing: { timeoutMs: 5000 }, * }), []); // Stable reference - options don't change * * return ( * * * * ); * }; * ``` */ options?: RoomOptions; /** Children nodes. */ children?: ReactNode | ReactNode[] | null; } /** * React Context Provider that makes a specific {@link Room} available to child components. * * The provider automatically handles room attachment/detachment and provides the room * instance to child components through room-specific hooks like {@link useMessages}, * {@link usePresence}, {@link useTyping}, etc. * * Multiple providers for the same room (with same options) share the same underlying * room instance through reference counting, making it safe to have multiple components * using the same room simultaneously. * * When the first {@link ChatRoomProvider} for a room mounts, it creates * and attaches the room. When the last provider unmounts, it releases the room. * @param props - The props for the ChatRoomProvider component. * @param props.name The name of the room. * @param props.options Overriding options to use when creating the room. * @param props.children The child components to be rendered within this provider. * @returns A React element that provides the room context to its children * @throws An {@link Ably.ErrorInfo} with {@link chat-js!ErrorCode.ReactHookMustBeUsedWithinProvider | ReactHookMustBeUsedWithinProvider} When used outside of a {@link ChatRoomProvider} * @throws An {@link Ably.ErrorInfo} with {@link chat-js!ErrorCode.RoomExistsWithDifferentOptions | RoomExistsWithDifferentOptions} if room exists with different options * @example Basic usage * ```tsx * import * as Ably from '@ably/pubsub-device'; * import React, { useMemo } from 'react'; * import { ChatClient } from '@ably/chat'; * import { * ChatClientProvider, * ChatRoomProvider, * useMessages, * useRoom, * } from '@ably/chat/react'; * * const chatClient: ChatClient; // existing ChatClient instance * * // Child component using room functionality * const ChatInterface = () => { * const { roomName } = useRoom(); * const { sendMessage } = useMessages(); * * return ( *
*

Chat Room: {roomName}

* *
* ); * }; * * const BasicExample = () => { * return ( * * * * * * ); * }; * ``` * @example Providing custom room options * ```tsx * import { ChatClientProvider, ChatRoomProvider } from '@ably/chat/react'; * import { ChatClient } from '@ably/chat'; * * const chatClient: ChatClient; // existing ChatClient instance * * // Example with room options (properly memoized) * const CustomOptions = () => { * // Memoize options to prevent room recreation * const roomOptions = useMemo(() => ({ * typing: { * timeoutMs: 10000 // 10 second typing timeout * }, * }), []); // Empty dependency array = stable reference * * return ( * * * * * * ); * }; * ``` */ export declare const ChatRoomProvider: ({ name: roomName, options, children }: ChatRoomProviderProps) => React.ReactElement;