-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[data grid] updateRows triggers renderCell too many times #7821
Comments
You need to wrap your custom const CustomCellRenderer = ({ value }) => {
return value;
};
const MemoizedCellRenderer = React.memo(
CustomCellRenderer,
(prevProps, nextProps) => {
return prevProps.value === nextProps.value;
}
);
const columns = [
{
field: 'id',
renderCell: (params) => {
return <MemoizedCellRenderer {...params} />;
},
},
]; By doing so, you can substantially reduce the number of times that the custom cell is re-rerended. |
@m4theushw Thank you. It helps, the performances are better, even if it feels tedious and can be difficult to implement in more complex use cases. It doesn't feel "right", you see what I mean? It seems to be really easy to stumble upon this performance problem, since it manifests itself quickly with not-so-large-and-complex tables. If there is no plan to fix this behavior in the foreseeable future, it could be worth it to mention this workaround in the doc don't you think? |
I understand your pain, however, since we allow to use custom cell renderers (with |
Duplicates
Latest version
Steps to reproduce 🕹
Link to live example: https://stackblitz.com/edit/react-ts-ocmxqz?file=App.tsx
Steps:
Current behavior 😯
Each click on "Update" triggers 8 times the same
renderCell
function.In the project I'm working on, it's causing real performance issues (and for an unknown reason, it "only" renders each cell 4 times, not 8).
Expected behavior 🤔
Since the button click just calls
grid.current.updateRows([{ id: 'abc' }]);
, I would expect the render to occur 1 or 0 times, not 2+.Context 🔦
I was having performance issues on what I would call a average+ complex table: 5 columns with 5 renderCells, many buttons that appear and disappear dependending on the user's actions.
There could be several causes of performance issues but rendering each cells 4 to 8 times surely doesn't help :p
I'm still in the process of learning React and MUI, so please don't be too harsh if I missed an issue or something in the doc. I saw several issues talking about performance problems, and
renderCell
often seems involved. I don't really know if they are related to my problem.Aside to this issue, any advices on how to improve the performance when using
renderCells
would be greatly appreciated.Your environment 🌎
npx @mui/envinfo
Order ID 💳 (optional)
59183
The text was updated successfully, but these errors were encountered: