This component is used to display the users. Once a new user is added from another component usersUpdated gets toggled and a call is made to backend to fetch all the users again which contains the newly added user and display in the Datagrid. But the datagrid does not display any record and distorts the datagrid UI. If the page is refreshed or some other action is performed in Datagrid like changing the pageSize displays all the records properly.
const UsersDisplayTable = (props) => {
const usersUpdated = props.usersUpdated;
const [columns, setColumns] = useState(
[
{
field: 'email',
headerName: 'Email',
align: "left",
headerAlign: "left",
flex: 1,
filterable: true
},
{
field: 'dateOfBirth',
headerName: 'Date Of Birth',
align: "center",
headerAlign: "center",
flex: 0.75,
filterable: false,
sortable: false,
valueFormatter: (params) => {
const valueFormatted = moment(
new Date(params.row.dateOfBirth)).format(
'DD MMM YYYY');
return `${valueFormatted}`;
}
},
{
field: "actions",
headerName: "Actions",
sortable: false,
filterable: false,
align: "center",
headerAlign: "center",
flex: 0.75,
renderCell: (params) => {
return (
<>
<EditUserIcon
onClick={(e) => props.editUser(
e, params.row)}
title='Edit'/>
</>
);
}
}
]
);
const [allUsers, setAllUsers] = useState([]);
useEffect(() => {
axios
.get("/get-all-users")
.then(data => {
setAllUsers(data.data.data)
}).catch(error => {})
}, [usersUpdated])
return (
<>
<DataGrid
sortingOrder={["desc", "asc"]}
rows={allUsers} columns={columns}
disableSelectionOnClick
disableColumnSelector />
</>
);
}
export default UsersDisplayTable;
after adding dynamic row or user

Is this a limitation of Material UI Datagrid?
