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

这样就没问题了

相关推荐
程序员爱钓鱼13 分钟前
Node.js 编程实战:测试与调试 —— Mocha / Jest / Supertest 使用指南
前端·后端·node.js
一勺菠萝丶18 分钟前
芋道项目部署:前端写死后端地址 vs Nginx 反向代理
前端·nginx·状态模式
pas13634 分钟前
30-mini-vue 更新 element 的 props
前端·javascript·vue.js
魁首1 小时前
OpenAI Codex 深入剖析:下一代 AI 编程助手的架构与原理
前端·openai·ai编程
火星数据-Tina1 小时前
如何构建一个支持多终端同步的体育比分网站?
大数据·前端·数据库·websocket
IT_陈寒1 小时前
React 19 实战:5个新特性让你的开发效率提升50%!
前端·人工智能·后端
GuMoYu1 小时前
el-date-picker限制选择范围
前端·javascript·vue.js
冴羽1 小时前
JavaScript Date 语法要过时了!以后用这个替代!
前端·javascript·node.js
加油乐1 小时前
react使用Ant Design
前端·react.js·ant design