MUI DataGrid warns that rows is an object when it expects an array
Warning: Failed prop type: Invalid prop `rows` of type `object` supplied to `ForwardRef(DataGrid)`, expected `array`.Short answer
The DataGrid rows prop expects an array of objects. The warning appears when you pass something else that typeof reports as object: the whole API response instead of its list, an object keyed by id, or a promise from an async call. Pass the array itself, and keep its reference stable between renders.
Fix it fast
1Find out which cause you have
Print what you pass to rows, with its type, right before the grid.
console.log(Array.isArray(rows), typeof rows, rows);2Match what you see, then jump to its fix
- 1
The log shows false, 'object', and a value like { data: [...], total: 40 }The whole response object is passed instead of the list inside itFix - 2
The log shows an object like { '1': {...}, '2': {...} }The data is an object keyed by idFix - 3
The log prints Promise { <pending> }A promise or an async function result is passedFix
- 1
What does the error look like?
Warning: Failed prop type: Invalid prop `rows` of type `object` supplied to `ForwardRef(DataGrid)`, expected `array`.
Cause 1 of 3
The whole response object is passed instead of the list inside it
1Check
Many APIs wrap the list, and axios adds its own wrapper, so the array sits one or two levels down.
console.log(response.data);2Fix
Read the array out of the response and give the grid that. Start the state as an empty array so the first render is valid.
const [rows, setRows] = useState([]);
useEffect(() => {
axios.get('/api/users').then((res) => setRows(res.data.items));
}, []);
<DataGrid rows={rows} columns={columns} />3Verify
The warning disappears and the grid shows the rows.
console.log(Array.isArray(rows)); // trueConfirmed by mui.com
Cause 2 of 3
The data is an object keyed by id
1Check
Stores that keep records by id (normalised state) give you a map, and the grid wants a list. The same page says each row needs an id.
console.log(Object.keys(rows).slice(0, 3));2Fix
Convert the map to an array with Object.values. If the id is not stored in the record, copy it in, or tell the grid where it is with getRowId.
const list = useMemo(() => Object.values(rowsById), [rowsById]);
<DataGrid rows={list} columns={columns} getRowId={(row) => row.uid} />3Verify
The warning is gone and each row appears once.
console.log(Array.isArray(list)); // trueConfirmed by mui.com
Cause 3 of 3
A promise or an async function result is passed
1Check
An async function always returns a promise, which is an object. Passing its call result to rows hands the grid the promise.
console.log(rows instanceof Promise);2Fix
Await the call inside an effect, store the resolved array in state, and pass that state.
useEffect(() => {
let ignore = false;
loadRows().then((data) => { if (!ignore) setRows(data); });
return () => { ignore = true; };
}, []);3Verify
rows is an array on every render and the warning no longer prints.
console.log(Array.isArray(rows)); // trueConfirmed by mui.com
How do I stop it coming back?
- Log or assert Array.isArray(rows) once while building the screen, before you wire the grid.
- Initialise table state with [] and never with null or an empty object.
- Keep the rows reference stable between renders, as the docs ask; build derived arrays with useMemo.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- TaskvareA task and project-management suite: React on the web, Flutter on mobile, TypeScript underneath.
Related fixes
Web apps
The MUI X Data Grid ignores or rejects getRowId
Selection or updates affect the wrong rows
The Data Grid reads each row's id from a property called id by default.
3 causes, each with a fixWeb apps
Module not found for antd/dist/antd.less after upgrading to Ant Design 5
Module not found: Error: Can't resolve 'antd/dist/antd.less'
Ant Design 5 dropped Less and the bundled CSS file for CSS-in-JS, so antd/dist/antd.less no longer exists.
3 causes, each with a fixWeb apps
Astro Code component fails inside a React component
Astro components cannot be rendered directly via function call
Astro components such as Code only exist on the server and render static HTML.
2 causes, each with a fixWeb apps
React shows Attempted import error when importing a component or function
Attempted import error:
The build found the file but not the name you asked for.
2 causes, each with a fixWeb apps
How to catch and handle a 422 from Axios in a Redux thunk
action.error.message is 'Rejected' and action.payload is undefined
A 422 means the server read the request but cannot process its content, so repeating it unchanged fails again.
4 causes, each with a fixWeb apps
axios gets 429 Too Many Requests from a React app
429 (Too Many Requests)
A 429 comes from the server or an API gateway, not from axios: your client sent too many requests in a window.
4 causes, each with a fix