# @lilith/messaging-hooks React Query hooks for real-time messaging features in the lilith-platform. ## Features - **Message Management**: Fetch, send, and manage chat messages with optimistic updates - **Thread Management**: List and manage conversation threads - **Typing Indicators**: Real-time typing status with debouncing - **Presence Tracking**: User online/offline status with heartbeat mechanism - **React Query Integration**: Built-in caching, automatic refetching, and optimistic updates ## Installation ```bash pnpm add @lilith/messaging-hooks ``` ## Prerequisites - React 18+ - @tanstack/react-query v5+ - @lilith/websocket-client ## API Reference ### useMessages Fetch messages for a specific thread with React Query caching. ```tsx import { useMessages } from '@lilith/messaging-hooks' function MessageList({ threadId }) { const { data, isLoading } = useMessages(threadId) return (
{data?.map(message => ( ))}
) } ``` ### useSendMessage Send messages with optimistic updates. ```tsx import { useSendMessage } from '@lilith/messaging-hooks' function MessageInput({ threadId }) { const { mutate } = useSendMessage(threadId) const handleSend = (content: string) => { mutate({ roomId: threadId, content, senderId: currentUser.id }) } return handleSend(e.target.value)} /> } ``` See package source for full API documentation. ## License MIT