I’m working on a project where I need to pull data from Airtable and show it in a Material-UI DataGrid. The data is coming through fine when I check the console, but the grid only shows column headers and no actual rows.
Here’s my current setup:
import React, { useEffect, useState } from "react";
import { makeStyles } from "@material-ui/styles";
import { Container } from "@material-ui/core";
import { DataGrid } from "@mui/x-data-grid";
import Airtable from "airtable";
const database = new Airtable({ apiKey: "your-key" }).base("your-base-id");
const useStyles = makeStyles(() => ({
wrapper: {
marginTop: "5vh",
},
}));
const columns = [
{ field: "id", headerName: "Record ID", width: 100 },
{ field: "title", headerName: "Company Name", width: 200 },
{ field: "city", headerName: "City", width: 120 },
{ field: "region", headerName: "Region", width: 120 },
];
export default function CompanyList() {
const classes = useStyles();
const [data, setData] = useState([]);
useEffect(() => {
database("Companies")
.select({
maxRecords: 5,
view: "Main view",
})
.eachPage((items, getNext) => {
setData(items);
console.log(items);
getNext();
});
}, []);
return (
<Container className={classes.wrapper}>
<p>Choose companies from the list below:</p>
{data && (
<DataGrid
rows={data}
columns={columns}
pageSize={10}
rowsPerPageOptions={[10]}
checkboxSelection
/>
)}
</Container>
);
}
The console shows the records properly but the grid stays empty. What am I missing here?