ant-design / pro-chat

🤖 Components Library for Quickly Building LLM Chat Interfaces.
https://pro-chat.antdigital.dev
MIT License
649 stars 78 forks source link

🐛[BUG] actions.render方法无法响应式执行 #200

Closed HongwuQz closed 3 months ago

HongwuQz commented 3 months ago

🐛 bug 描述

actions.render方法中无法获取异步数据来根据动态数据自定义actionsBar

📷 复现步骤

只要actions.render方法中使用了异步获取的数据,就会一直得不到更新

🏞 期望结果

actions.render中可以依赖函数中使用到的state重新被调用

💻 复现代码

export const Chat = () => {
  const [actionsContents, setActionsContents] = useState<string[]>([]);

  useEffect(() => {
    fetch('/xxx').then((res: string[]) => {
      setActionsConfig(res)
    })
  }, [])

  return (
    <ProChat
      actions={{
        render: () => {
          // 这里的actionsContents会一直是默认值
          return actionsContents.map(actions => (
            <button>actions</button>
          ))
        }
      }}
    />
  )
}

© 版本信息