Skip to content

setTyping is not a function #184

@jinsihou19

Description

@jinsihou19

Version information (版本信息)

  • ChatUI
  • ChatUI Version: 3.0.0
  • React Version: none
  • OS Version: -
  • Browser Version: -

Describe the bug (描述问题)
setTyping is not a function
TypeError: setTyping is not a function

Steps To Reproduce (重现步骤)

import React from "react";
import Chat, { Bubble, useMessages } from "@chatui/core";
import "@chatui/core/dist/index.css";

export default function App() {
  const { messages, appendMsg,setTyping } = useMessages([]);

  function handleSend(type, val) {
    if (type === "text" && val.trim()) {
      appendMsg({
        type: "text",
        content: { text: val },
        position: "right",
      });

      setTyping(true);

      // 模拟收到消息
      setTimeout(() => {
        appendMsg({
          type: "text",
          content: { text: "Bala bala" },
        });
      }, 1000);
    }
  }

  function renderMessageContent(msg) {
    const { type, content } = msg;

    // 根据消息类型来渲染
    switch (type) {
      case "text":
        return <Bubble content={content.text} />;
      default:
        return null;
    }
  }

  return (
    <Chat
      navbar={{ title: "智能助理" }}
      messages={messages}
      renderMessageContent={renderMessageContent}
      onSend={handleSend}
    />
  );
}

https://codesandbox.io/p/devbox/chatui-demo-forked-qssjtc

Link to minimal reproduction (最小化重现链接)

Expected behavior (期望的结果是什么)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions