Object containing chat state (messages, unreadCount) and
actions (sendMessage, clearUnread, loadChatHistory)
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>
);
}
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.