Hiyve Components - v1.0.0
    Preparing search index...

    Function useChat

    • Access in-room chat state and actions.

      Provides the list of chat messages, an unread message count, and actions to send messages, clear the unread counter, and load chat history.

      Returns {
          clearUnread: () => void;
          loadChatHistory: (cursor?: string | null) => Promise<{ hasMore: boolean }>;
          messages: ChatMessage[];
          sendMessage: (content: string) => void;
          unreadCount: number;
      }

      Object containing chat state (messages, unreadCount) and actions (sendMessage, clearUnread, loadChatHistory)

      • clearUnread: () => void
      • loadChatHistory: (cursor?: string | null) => Promise<{ hasMore: boolean }>
      • messages: ChatMessage[]
      • sendMessage: (content: string) => void
      • unreadCount: number
      import { useChat } from '@hiyve/rn-react';

      function ChatScreen() {
      const { messages, unreadCount, sendMessage, clearUnread } = useChat();
      const [text, setText] = useState('');

      useEffect(() => { clearUnread(); }, [clearUnread]);

      return (
      <View style={{ flex: 1 }}>
      <FlatList
      data={messages}
      renderItem={({ item }) => (
      <Text><Text style={{ fontWeight: 'bold' }}>{item.sender}:</Text> {item.text}</Text>
      )}
      />
      <View style={{ flexDirection: 'row' }}>
      <TextInput value={text} onChangeText={setText} style={{ flex: 1 }} />
      <Button title="Send" onPress={() => { sendMessage(text); setText(''); }} />
      </View>
      </View>
      );
      }