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

这样就没问题了

相关推荐
大模型铲屎官34 分钟前
告别页面刷新!如何使用AJAX和FormData优化Web表单提交
前端·javascript·ajax·html·编程·页面刷新·表单提交
无限大.4 小时前
前端知识速记--HTML篇:src和href
前端·html
子非鱼9214 小时前
两栏布局、三栏布局、水平垂直居中
前端·javascript·css
程序猿小D5 小时前
第三百五十八节 JavaFX教程 - JavaFX滑块
java·前端·数据库
GISer_Jing6 小时前
React中useState()钩子和函数式组件底层渲染流程详解
前端·react.js·前端框架
私人珍藏库7 小时前
Google Chrome-便携增强版[解压即用]
前端·chrome
我的青春不太冷8 小时前
【实战篇章】深入探讨:服务器如何响应前端请求及后端如何查看前端提交的数据
运维·服务器·前端·学习
Anlici8 小时前
2025前端高频面试题--CSS篇
前端·css
追光少年33229 小时前
Learning Vue 读书笔记 Chapter 4
前端·javascript·vue.js
软件2059 小时前
【Vite + Vue + Ts 项目三个 tsconfig 文件】
前端·javascript·vue.js