import React, { useState } from 'react'; import { InputNumber, Table } from 'antd'; import type { TableColumnsType, TableProps } from 'antd'; type TableRowSelection = TableProps['rowSelection']; const RenderTimes = () => { const timesRef = React.useRef(0); timesRef.current += 1; return {timesRef.current}; }; interface DataType { key: React.Key; name: string; age: number; address: string; } const shouldCellUpdate = (record: any, prevRecord: any) => record !== prevRecord; const columns: TableColumnsType = [ { title: 'Name', dataIndex: 'name', shouldCellUpdate, }, { title: 'Age', dataIndex: 'age', shouldCellUpdate, }, { title: 'Address', dataIndex: 'address', shouldCellUpdate, render: (addr) => ( <> {addr} ), }, ]; function genData(count: number) { const data: DataType[] = []; for (let i = 0; i < count; i++) { data.push({ key: i, name: `Edward King ${i}`, age: 32, address: `London, Park Lane no. ${i}`, }); } return data; } const App: React.FC = () => { const [data, setData] = useState(genData(50)); const [selectedRowKeys, setSelectedRowKeys] = useState([]); const onSelectChange = (newSelectedRowKeys: React.Key[]) => { console.log('selectedRowKeys changed: ', newSelectedRowKeys); setSelectedRowKeys(newSelectedRowKeys); }; const rowSelection: TableRowSelection = { selectedRowKeys, onChange: onSelectChange, }; return ( <> { setData(genData(cnt || 0)); }} /> ); }; export default App;