# antd表格性能差的解决方案 ##### 性能差原因:透過Performance监控得知,大量的mouse event和function call,严重阻塞渲染线程。 ##### 解決方法:使用antd的Table里的components属性将自定义单元格,阻止onMouseEnter, onMouseLeave的透传,解决后表格滚动时性能会提升3倍。 ``` // 注意TdCell要提到DataTable作用域外声明 const TdCell = (props: any) => { // onMouseEnter, onMouseLeave在数据量多的时候,会严重阻塞表格单元格渲染,严重影响性能 const { onMouseEnter, onMouseLeave, ...restProps } = props; return <td {...restProps} />; }; const DataTable: React.FC<tableType> = (props) => { const { columns,dataSource } = props; return <Table columns={columns} dataSource={dataSource} components={{ body: { cell: TdCell }, }} /> ); }; export default DataTable; ``` 链接:https://juejin.cn/post/7063332320339099678
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up