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

这样就没问题了

相关推荐
Jinuss10 分钟前
源码分析之React中ReactDOMRoot实现
前端·javascript·react.js
web守墓人20 分钟前
【前端】vue3的指令
前端
想起你的日子1 小时前
EFCore之Code First
前端·.netcore
框架图1 小时前
Html语法
前端·html
深耕AI1 小时前
【wordpress系列教程】07 网站迁移与备份
运维·服务器·前端·数据库
joan_852 小时前
input禁止自动填充
前端·elementui·vue
林间风雨2 小时前
layui 2.9.16 版本,根据字段字数最大数,表格自适应字段宽度
前端·javascript·layui
木子啊2 小时前
HTML防窥技巧:让源码难以偷窥
前端·html·查看源码·禁止查看源码
梦6503 小时前
前端路由守卫:掌控页面跳转的 “守门人”
前端