【发布时间】:2022-10-15 02:46:14
【问题描述】:
所以我正在尝试使用我的 API 中的数据填充 Datagrid:
const [listofInvoices, setListofInvoices] = useState({id: 0})
useEffect(()=>{
axios.get("http://localhost:3001/invoices").then((response)=>{
setListofInvoices(response.data) //State which contains the response from the API request
});
}, [])
const rows: GridRowsProp = [listofInvoices];
const columns: GridColDef[] = [
{ field: "invNumber", headerName: "Invoice Number", width: 150 },
{ field: "invAmount", headerName: "Invoice Amount", width: 150 }
];
然后我使用以下代码显示 DataGrid:
<div style={{margin:'auto', height: 450, width: '95%' }}>
<DataGrid rows={rows} columns={columns} getRowId={(row) => row.id} components={{ Toolbar: GridToolbar }} />
</div>
但是即使我的所有行都有一个 id,我仍然会收到此错误: Console Error
【问题讨论】:
标签: reactjs material-ui datagrid