useCreateChatContext

Creates a memoized ChatContext value from the provided props. This prevents unnecessary re-renders of consumers by only updating the context when relevant values change.

Best Practices

  • Avoid calling this hook directly; the Chat component manages it internally.
  • Access the context value through useChatContext instead of using this hook.
  • Ensure all required ChatContextValue properties are provided to avoid runtime errors.
  • Keep the input values stable (e.g., avoid inline object creation) to maximize memoization benefits.

Usage

useCreateChatContext.ts
import { useCreateChatContext } from "stream-chat-react-native";

const chatContext = useCreateChatContext({
  appSettings,
  channel,
  client,
  connectionRecovering,
  enableOfflineSupport,
  isMessageAIGenerated,
  isOnline,
  mutedUsers,
  setActiveChannel,
});

This is an internal hook used by the Chat component to build the ChatContext value. You should not need to call this hook directly; use useChatContext to consume the context instead.

Parameters

The hook accepts a single object with the following properties matching ChatContextValue:

NameTypeRequiredDescription
appSettingsAppSettingsAPIResponse | nullYesApplication settings returned from Stream.
channelChannelNoThe currently active channel instance.
clientStreamChatYesThe Stream Chat client instance.
connectionRecoveringbooleanYesWhether the connection is currently recovering.
enableOfflineSupportbooleanYesWhether offline support is enabled.
isMessageAIGenerated(message: MessageType) => booleanNoFunction to determine if a message was AI-generated.
isOnlineboolean | nullYesWhether the client currently has an active connection.
mutedUsersMute[]YesList of muted users for the current user.
setActiveChannel(newChannel?: Channel) => voidYesCallback to set the active channel.

Returns

TypeDescription
ChatContextValueA memoized context value object for the ChatContext provider.