react报错 Uncaught Invariant Violation: Unable to find node on an unmounted compone

在采用ant.design的Table组件时,给table组件赋值了rowkey为id

<Tablecolumns={columns}dataSource={this.state.data}pagination={false}rowKey={record => record.id}
/>

默认的data中有初始数据,显示效果如下,这些默认的数据都是有id的

点击新建绘本,新建两个绘本,新建的数据条目没有id,数据格式如下

  newMember = (image, audio) => {const newData = [...this.state.data];newData.push({key: `NEW_TEMP_ID_${this.index}`,editable: false,isNew: true,image: image,audio: audio,});this.index += 1;this.setState({ data: newData }, () => {this.props.onChange(this.state.data);});}

新建成功两条绘本数据

此时控制台会报如下警告,当时并不以为然

当时只是新生疑惑,并不清楚怎么会有两条key为2的数据,然后删除第一个条目的时候就没有反应,删除第三个条目成功,再删除第一个条目的时候就报错

后来发现 初始的第一条数据id为2,也就是key为2,后来新建了两条数据,设置了rowkey为id,ant.design的Table组件当检测到rowkey为undefined的情况下会自动将rowkey设置为index,所以第三条数据key为2,与第一条数据相同,导致后来删除数据的时候按照key操作会出现渲染错误的情况,将Table的rowKey设置为index之后就会有不同且唯一的key

//recordKey部分实现_this.getRecordKey = function (record, index) {var rowKey = _this.props.rowKey;var recordKey = typeof rowKey === 'function' ? rowKey(record, index) : record[rowKey];(0, _warning["default"])(recordKey !== undefined, 'Table', 'Each record in dataSource of table should have a unique `key` prop, ' + 'or set `rowKey` of Table to an unique primary key, ' + 'see https://u.ant.design/table-row-key');return recordKey === undefined ? index : recordKey;};

react报错 Uncaught Invariant Violation: Unable to find node on an unmounted compone相关推荐

  1. hive日志位置(日志定位报错:Failed with exception Unable to move sourcehdfs://namenode/tmp/hive-pmp_bi/h)...

    Hive中的日志分为两种 1. 系统日志,记录了hive的运行情况,错误状况. 2. Job 日志,记录了Hive 中job的执行的历史过程. 日志查看方法 1,在本地运行机器上 hive日志存储位置 ...

  2. 小程序组件报错Uncaught TypeError: Cannot read property 'name' of undefined

    小程序组件报错Uncaught TypeError: Cannot read property 'name' of undefined Component({/*** 组件的属性列表*/propert ...

  3. vue报错 Uncaught (in promise) NavigationDuplicated {_name:““NavigationDuplicated“... 的解决方法

    vue报错 Uncaught (in promise) NavigationDuplicated {_name:""NavigationDuplicated"... 的解 ...

  4. Git报错解决:fatal: unable to access ‘https://github.com/...‘: OpenSSL SSL_read:..., errno 10054

    Git报错解决:fatal: unable to access 'https://github.com/-': OpenSSL SSL_read: Connection was reset, errn ...

  5. JS报错: Uncaught SyntaxError: Invalid shorthand property initializer

    JS报错: Uncaught SyntaxError: Invalid shorthand property initializer 如果你的代码报错以上提示, 那么就去检查一下, 对应的代码是不是把 ...

  6. React报错:Too many re-renders

    React报错:Too many re-renders. React limits the number of renders to prevent an infinite loop. Too man ...

  7. js代码中for循环里绑定onclick事件报错Uncaught TypeError Cannot set properties of undefined (setting ‘className‘)

    jsfor循环里绑定onclick事件报错Uncaught TypeError Cannot set properties of undefined (setting 'className') 我想要 ...

  8. 【问题篇】Springboot解决报错“java.sql.SQLException: Unable to load authentication plugin ‘caching_sha2_passw”

    场景:从代码仓库拉取以前的代码,运行时发现报错"java.sql.SQLException: Unable to load authentication plugin 'caching_sh ...

  9. Unity 报错之 ToLua打包:Unable to find tolua DllNotFoundException: tolua

    Unity 报错之 ToLua打包:Unable to find tolua DllNotFoundException: tolua 最近在学习使用LuaFramework框架,使用其打出的安卓包运行 ...

最新文章

  1. 万字长文带你了解推荐系统全貌!
  2. 五分钟看懂UML类图与类的关系详解
  3. 文献记录(part16)--Learning Bayesian Network Classifiers: Searching in a Space of Partially ...
  4. Java 8 新特性:扩展注解(类型注解和重复注解)
  5. Java中TreeMap和TreeSet的底层实现
  6. c语言标识符的文法表示,第三章文法和语法[lly]3.ppt
  7. Docker的Hadoop-Hbase的 Docker Hub文档
  8. 如何向Word中插入代码块
  9. windows server上存储提示“由于管理员设置的策略,该磁盘处于脱机状态”
  10. dpkg检查某个应用是否已安装
  11. Java Web前后端分离架构
  12. java工作流activity_activity 工作流学习(一)
  13. ABB伺服驱动调试(四)
  14. 6种摆脱百度竞价恶意点击的技巧
  15. Systemverilog中@和wait区别
  16. obj转stl_STL转STP的方法视频教程,OBJ格式转STP或者IGS开模具格式的过程,STL转STP软件介绍...
  17. COM---EXE中的服务器
  18. 将彩色图片分离为RGB三个通道的灰度图,并输出
  19. python第六章习题答案
  20. 重磅!新职业技能证书来了,让你高薪就业

热门文章

  1. 华为鸿蒙p20pro,华为手机nova5pro和P20pro究竟哪一款值得入手?
  2. python中判断类型函数isinstance()
  3. ios 9.1之后 微信第三方登陆“This app is not allowed to query for scheme weixin”问题
  4. 蜘蛛网拥抱商品期货_方正证券_CTA专题研究
  5. python-py文件在windows下乱码
  6. 从十大经典故事中学员工管理和激励
  7. 领导让你即兴讲两句?别愁!【讲话框架】学起来~
  8. IK Multimedia MODO DRUM for Mac(鼓虚拟乐器)
  9. Scrapy 框架获取豆瓣电影的信息(包括图片)和电影评论-1
  10. Idea 2022 搭建Struts2 框架手把手教程!新鲜出炉!!