alibaba / ChatUI

The UI design language and React library for Conversational UI
https://chatui.io
MIT License
2.64k stars 280 forks source link

BUG:<chat/>组件使用composer渲染自定义组件<inputarea/>之后,每次发送完消息,我自己定义的<inputarea/>就会强制刷新 #128

Open ZongYan30 opened 11 months ago

ZongYan30 commented 11 months ago

Version information (版本信息) @2.4.2

Describe the bug (描述问题) BUG:组件使用composer渲染自定义组件之后, 每次发送完消息,我自己定义的就会强制刷新,导致里面刚打印的文本会随着刷新丢失。

Steps To Reproduce (重现步骤) bug:演示: bug

具体代码实现如下: 1.的使用,以及自定义composer

01 02

2.项目页面

03

Link to minimal reproduction (最小化重现链接) 有一篇csdn的博客,也有类似的自定义composer重新强制渲染的说明: https://blog.csdn.net/runrun117/article/details/118223631 Expected behavior (期望的结果是什么) 有人可以给出解决建议和思路

ylinwind commented 10 months ago

遇到了,临时处理在组件外加了个变量记录输入的值, const [inputValue, setInputValue] = useState(localInputValue)

liyanping111 commented 5 months ago

@ylinwind 代码是怎么写的呀

NOBOUNDer commented 2 months ago
const MemoizedCustomComposer = useCallback(
    (props: any) => (
      <CustomComposer {...props}  />
    ),
    []
  )

 <Chat
        Composer={MemoizedCustomComposer}
        messages={messages}
        renderMessageContent={renderMessageContent}
        onSend={handleSend}
        />

使用useCallback包裹自定义composer,依赖项设置为[]