classes prop needs to be memoized
See original GitHub issueMaybe I am interpreting this wrong, but I believe that if I pass a classes
prop to a component wrapped with withStyles
, that component always re-renders with the parent, even if no props change.
const myClasses = { test: 'myClass' };
class MyComponent extends React.PureComponent {
render() {
return (
<MySecondComponent classes={myClasses} />
);
}
}
I believe what’s happening is when MySecondComponent is checked for updates, withStyles
generates a new object despite the fact that its classes
prop has not changed.
https://github.com/mui-org/material-ui/blob/v1-beta/packages/material-ui/src/styles/withStyles.js#L234
This causes the SecondComponent to always re-render, despite its props not changing.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:11 (11 by maintainers)
Top Results From Across the Web
mui/material-ui - classes prop needs to be memoized - GitHub
I believe what's happening is when MySecondComponent is checked for updates, withStyles generates a new object despite the fact that its classes ......
Read more >How to Implement Memoization in React to Improve ... - SitePoint
Memoization is a good technique for improving performance in React apps by avoiding unnecessary re-renders of a component if its props or state ......
Read more >Memoization in React js - Topcoder
Memoization Using Memo Memo allows us to implement memoization in functional components since PureComponents can only be used in class ...
Read more >How to Memoize Components in React | by Ross Bulat - Medium
We will cover how to deal with callback functions as props (state included) further down with the useCallback() Hook.
Read more >What is Memoization? How and When to ... - freeCodeCamp
We also have a child component to which we're passing a prop name which is a string. import React from "react" import Child...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yep: #8142
PR open, sorry for the delay. I had trouble getting
yarn build
to work on my machine, so I just usedbabel-es2015 stage-0 react
and replaced thenode_module
on my machine to test. Worked great. I think it only added ~600 bytes for an uncompressed transpile.