import React from 'react'; import _ from 'lodash'; interface Field { key: string; label: string; transform?: (text: string) => string; } interface Props { items?: any[]; fields: Field[]; handleRowClick?: (index: number) => void; } const getItemField = (item: any, field: Field) => { const value = _.get(item, field.key); return field.transform ? field.transform(value) : value; }; const ListTable: React.FC = ({ items = [], fields, handleRowClick = () => {} }) => { if (!items.length) return
No data
; return ( {fields.map(field => )} {items.map((item, index) => ( handleRowClick(index)} > {fields.map(field => ( ))} ))}
{field.label}
{getItemField(item, field)}
); }; export default ListTable;