Commit bb54d5a2 by HoMeTown

fix: 解决当records为空时的报错问题

parent e6941309
...@@ -49,7 +49,7 @@ export const ChatContent: React.FC = () => { ...@@ -49,7 +49,7 @@ export const ChatContent: React.FC = () => {
itemContent={(index, record) => ( itemContent={(index, record) => (
<ChatItem record={record} key={record.originalData?.groupId} /> <ChatItem record={record} key={record.originalData?.groupId} />
)} )}
initialTopMostItemIndex={records.length - 1} // 初始滚动到底部 initialTopMostItemIndex={allItems.length - 1} // 初始滚动到底部
followOutput="smooth" // 新消息时平滑滚动到底部 followOutput="smooth" // 新消息时平滑滚动到底部
/> />
</motion.div> </motion.div>
......
...@@ -10,6 +10,8 @@ const initialState: ChatState = { ...@@ -10,6 +10,8 @@ const initialState: ChatState = {
function processApiResponse(data: OriginalRecord[]): ChatRecord[] { function processApiResponse(data: OriginalRecord[]): ChatRecord[] {
const chatRecord: ChatRecord[] = [] const chatRecord: ChatRecord[] = []
if (data.length === 0)
return chatRecord
data.forEach((record) => { data.forEach((record) => {
chatRecord.push({ chatRecord.push({
type: 'question', type: 'question',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment