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,
});
Note:

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:

Name Type Required Description
appSettings AppSettingsAPIResponse | null Yes Application settings returned from Stream.
channel Channel No The currently active channel instance.
client StreamChat Yes The Stream Chat client instance.
connectionRecovering boolean Yes Whether the connection is currently recovering.
enableOfflineSupport boolean Yes Whether offline support is enabled.
isMessageAIGenerated (message: LocalMessage) => boolean No Function to determine if a message was AI-generated.
isOnline boolean | null Yes Whether the client currently has an active connection.
mutedUsers Mute[] Yes List of muted users for the current user.
setActiveChannel (newChannel?: Channel) => void Yes Callback to set the active channel.

Returns

Type Description
ChatContextValue A memoized context value object for the ChatContext provider.