美文网首页
Warning: `columns.render` return

Warning: `columns.render` return

作者: 南土酱 | 来源:发表于2022-09-05 11:04 被阅读0次

今天写 react antd 的表格 的时候,遇到这样一个问题
Warning:columns.renderreturn cell props is deprecated with perf issue, please useonCell` instead.

一般出现在 Antd 表格 的单元格渲染的时候,不正确的写法才会导致的
我的问题是 在编写 单元格 的按钮功能的时候:
tables.png
上边是 antd 官网案例,此处进行了缩减来说明问题出现

 return (_, record) => {
  return  true ? '' :'' ;
}
此处是 return 要渲染的组件。
可以包括的内容 string,int ,或者单个 的组件。
从上图来看,都是一个 元素包裹着所有子元素

利用span 来包裹
<span>
            <Typography.Link
              onClick={() => save(record.key)}
              style={{
                marginRight: 8,
              }}
            >
              Save
            </Typography.Link>
            <Popconfirm title="Sure to cancel?" onConfirm={cancel}>
              <a>Cancel</a>
            </Popconfirm>
  </span>

而我本身是 返回两个 Button 
 return (_, record) => {
  return  true ? '' :  <Button ><Button > ;
}

这样会导致错误发生,正确的做法可以:
 return (_, record) => {
  return  true ? '' : <> <Button ><Button ></> ;
}
利用空标签来包裹。这样也不影响原来的组件样式。

这种写法 在 react 官网也有粗略的介绍

URL: 👉👉 https://zh-hans.reactjs.org/docs/fragments.html

相关文章

网友评论

      本文标题:Warning: `columns.render` return

      本文链接:https://www.haomeiwen.com/subject/mysinrtx.html