React 代码警告处理合集

2022-11-22  本文已影响0人  DDLH

项目收尾阶段,控制台警告得处理掉吧!

❌ Warning: Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()?

项目背景使用 rc-virtual-list 实现滚动加载无限长列表

排查原因,包裹的List.Item使的出现警告⚠️错误,解决将其替换成div元素

虚拟列表问题
❌ Each record in table should have a unique key prop,or set rowKey to an unique primary key.

项目背景,引用ant-design Table组件,一般情况下可以用官网提示的解决方法解决。

官方文档:https://ant.design/components/table-cn#table

ant-design Table

但是呢,在真实情况下,表头和表数据均来自于后端返回,也找不出主键来标注唯一值。这个时候使用了Math.random()生成唯一值。

return <Table rowKey={record => record.uid || Math.random()} />;

😄
若是家人们有更好的解决方法,可以留言~一起成长一起学习鸭

上一篇 下一篇

猜你喜欢

热点阅读