【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)}

这样就没问题了

相关推荐
星栈几秒前
我把售后模块砍到只剩 64 行:Rust 全栈 CRM 的 MVP 取舍实录
前端·后端·开源
玉宇夕落1 分钟前
懒加载与Suspense的学习
前端
用户1733598075376 分钟前
纯前端实现PDF合并、拆分、压缩:技术方案与踩坑记录
前端
工会代表7 分钟前
frps配置,以linux服务器以及windows客户端进行远程桌面内网穿透为例。
前端
用户713874229009 分钟前
Promise 与 Async Await 深度解析
前端
董董灿是个攻城狮11 分钟前
5分钟入门卷积算法
前端
用户580481700292813 分钟前
我用 MCP 给小程序开发做了个 AI 副驾驶,开源了
前端
雨季mo浅忆14 分钟前
记录利用Cursor快速实现Excel共享编辑
前端·excel
皮皮大人16 分钟前
Vue 3 响应式内核完全解密:reactive & effect 与 Vue 2 Watcher 史诗对决
前端·vue.js
LaughingZhu17 分钟前
Product Hunt 每日热榜 | 2026-05-31
前端·人工智能·经验分享·搜索引擎·chatgpt·html