Я переключился с таблицы Material-UI на MuiDataTable для простоты использования, но я вижу предупреждение, даже если компонент работает должным образом. С учетом сказанного меня беспокоят предупреждения.
Ниже приведен код для компонента:
import React from "react";
import CsvDownload from 'react-json-to-csv'
import MUIDataTable from "mui-datatables";
import { messageService } from "../services/order-item-service";
export default class OrderItemComponent2 extends React.Component {
state = {
data: [],
_columns: [],
Header: [],
totalCount: 10,
options: {
pageSize: 16,
page: 0,
filterType: "dropdown",
selectableRows: false,
responsive: "scroll",
resizableColumns: true,
key: ""
}
};
componentDidMount() {
this.subscription = messageService.getMessage().subscribe((message) => {
let result = message;
this.setState({ data: result.message });
this.setState({ Header: [
{
name: 'order_id',
options: {
customHeadRender: () => (
<th className='MuiTableCell-root MuiTableCell-head first-col'>Order Id</th>
),
customBodyRender: (value, i) => (
<span>{ value }</span>
)
}
},
{
name: 'order_item_id',
options: {
customHeadRender: () => (
<th className='MuiTableCell-root MuiTableCell-head sec-col'>Order Item</th>
)
}
},
{
name: 'product_id',
options: {
customHeadRender: () => (
<th className='MuiTableCell-root MuiTableCell-head bg-col'>Prod ID</th>
)
}
},
{
name: 'code_division',
options: {
customHeadRender: () => (
<th className='MuiTableCell-root MuiTableCell-head thr-col'>Div</th>
)
}
},
{
name: 'code_product',
options: {
customHeadRender: () => (
<th className='MuiTableCell-root MuiTableCell-head sm-col'>Prod Code</th>
)
}
},
{
name: 'quantity_due',
options: {
customHeadRender: () => (
<th className='MuiTableCell-root MuiTableCell-head mid-col'>Qty Due</th>
)
}
},
{
name: 'quantity_shipped',
options: {
customHeadRender: () => (
<th className='MuiTableCell-root MuiTableCell-head mid-col'>Qty Sh</th>
)
}
},
{
name: 'price',
options: {
customHeadRender: () => (
<th className='MuiTableCell-root MuiTableCell-head sm-col'>Price</th>
)
}
},
{
name: 'date_shipped',
options: {
customHeadRender: () => (
<th className='MuiTableCell-root MuiTableCell-head mid-col'>Dt Sh</th>
)
}
},
{
name: 'date_due',
options: {
customHeadRender: () => (
<th className='MuiTableCell-root MuiTableCell-head mid-col'>Dt Due</th>
)
}
},
{
name: 'customer_id',
options: {
customHeadRender: () => (
<th className='MuiTableCell-root MuiTableCell-head bg-col'>Cust ID</th>
)
}
},
{
name: 'ship_via',
options: {
customHeadRender: () => (
<th className='MuiTableCell-root MuiTableCell-head mid-col'>Ship Via</th>
)
}
},
{
name: 'value_due',
options: {
customHeadRender: () => (
<th className='MuiTableCell-root MuiTableCell-head sm-col'>Val Due</th>
)
}
},
{
name: 'value_shipped',
options: {
customHeadRender: () => (
<th className='MuiTableCell-root MuiTableCell-head sm-col'>Val Sh</th>
)
}
},
{
name: 'date_order',
options: {
customHeadRender: () => (
<th className='MuiTableCell-root MuiTableCell-head mid-col'>Dt Or</th>
)
}
},
{
name: 'date_modified',
options: {
customHeadRender: () => (
<th className='MuiTableCell-root MuiTableCell-head bg-col'>Dt Mod</th>
)
}
}]
});
this.setState({
totalCount: Math.ceil(this.state.data.length / this.state.pageSize)
});
});
}
componentWillUnmount() {
// unsubscribe to ensure no memory leaks
this.subscription.unsubscribe();
}
getOrderItem() {
this.setState({ data: messageService.getMessage() });
}
render() {
return (
<div>
<CsvDownload className='btn btn-primary' data={ this.state.data } />
<MUIDataTable
title="Order Item"
data={this.state.data}
columns={this.state.Header}
options={this.state.options}
/>
</div>
);
}
}
Как видите, я использую customHeadRender для создания пользовательских заголовков, и именно тогда предупреждение впервые появилось. Кроме этого, он работает, как и ожидалось.
![The following is a screenshot of the warning that I am receiving](https://i.stack.imgur.com/OSIjG.png)
Строка 33 - первый customHeadRender
Как обычно, заранее спасибо