【Ant Design】【List】

源码

javascript 复制代码
   <List
       style={{
          width: 600,
          height: 200,
          overflow: 'auto',
        }}
        header={
          <>
            <Typography.Text
              copyable={{
                text: file.response.join(',') || '',
              }}
            />
          </>
        }
        split={false}
        dataSource={file.response}
        renderItem={(item: any, index: number) => (
          <List.Item>
            <Typography.Text type="danger">{item}</Typography.Text>
          </List.Item>
        )}
      />

报错

Uncaught TypeError: Cannot read properties of null (reading 'key')

分析

第一反应是每个字项遍历出了问题

加上key,改为

复制代码
 <List.Item key={`${item}-${index}`}>
        <Typography.Text type="danger">{item}</Typography.Text>
   </List.Item>

依然报错,那就是原始数据有null,不支持了

将数据注入List组件时,再用String包一层,防止存在null

复制代码
 dataSource={file.response.map(String)}

这样就没问题了

相关推荐
胡萝卜术1 天前
力扣5. 最长回文子串
前端·javascript·面试
我星期八休息1 天前
网络编程—应用层HTTP协议
linux·运维·开发语言·前端·网络·网络协议·http
不好听6131 天前
前端路由完全指南(下篇):懒加载、History 栈与工程化实践
前端·react.js
圣光SG1 天前
Java Web入门基础知识笔记
java·前端·笔记
cyforkk1 天前
Vercel 绑定自定义域名极简配置指南
服务器·前端·网络
IT_陈寒1 天前
React useEffect依赖数组中埋的坑,这次终于让我逮到了
前端·人工智能·后端
FourAu1 天前
2026 前端突围指南:从 ESR 边缘渲染到封装 Web AI SDK,聊聊 AI 时代的职业进化
前端·人工智能
Zkeq1 天前
不止是聊天框:我用 EdgeOne Makers Agents 给烹饪 APP 加了一位能“改菜谱”的 AI 主厨
前端
咩咩啃树皮1 天前
第32篇:前端本地存储全解——Cookie、localStorage、sessionStorage 区别与实战
前端