loading
ตัวอย่างทำงานด้วยข้อมูลตัวอย่าง ไม่ต้องใช้เครือข่ายหรือช่องทาง
tsx
import { useYuvaChat } from "@/hooks/use-yuva-chat"
export function Inbox() {
const chat = useYuvaChat({
server={process.env.NEXT_PUBLIC_YUVA_SERVER}
channel={process.env.NEXT_PUBLIC_YUVA_CHANNEL},
})
return (
<ul>
{chat.conversations.map((conversation) => (
<li key={conversation.id}>
<button onClick={() => void chat.open(conversation.id)}>{conversation.subject}</button>
</li>
))}
</ul>
)
}การติดตั้ง
รันคำสั่งนี้ในโปรเจกต์ shadcn ไฟล์จะถูกคัดลอกไปเป็นโค้ดของคุณเอง
Shell
npx shadcn@latest add https://useyuva.com/r/use-yuva-chat.jsonShell
pnpm dlx shadcn@latest add https://useyuva.com/r/use-yuva-chat.jsonShell
yarn dlx shadcn@latest add https://useyuva.com/r/use-yuva-chat.jsonShell
bunx --bun shadcn@latest add https://useyuva.com/r/use-yuva-chat.jsonการใช้งาน
tsx
import { useYuvaChat } from "@/hooks/use-yuva-chat"
const chat = useYuvaChat({ server, channel })Props
UseYuvaChatOptions
| Prop | ชนิด |
|---|---|
server? | string |
channel? | string |
client? | YuvaClient |
identityToken? | IdentityTokenSource | null |
helpArticleId? | string |
YuvaChatState
| Prop | ชนิด |
|---|---|
loading | boolean |
error | unknown |
inbox | ClientInbox | null |
contact | ClientContact | null |
connection | ConnectionState["state"] |
conversations | ClientConversation[] |
hasMoreConversations | boolean |
loadMoreConversations | () => Promise<void> |
activeId | string | null |
conversation | ClientConversation | null |
open | (id: string | null) => Promise<void> |
removed | boolean |
threadLoading | boolean |
messages | YuvaChatMessage[] |
hasEarlier | boolean |
loadEarlier | () => Promise<void> |
typing | ClientMessage["author"] | null |
memberReadAt | string | null |
send | (input: YuvaChatSendInput) => Promise<void> |
retry | (id: string) => Promise<void> |
discard | (id: string) => void |
setTyping | (on: boolean) => void |
markRead | () => Promise<void> |
rate | (rating: Rating, comment?: string) => Promise<void> |
openAttachment | (attachment: ClientAttachment) => Promise<void> |
saveEmail | (email: string) => Promise<void> |
ส่วนที่ต้องพึ่งพา
การติดตั้งรายการนี้จะเพิ่มรายการต่อไปนี้ด้วย