Memo propsAreEqual is good practice to use?
See original GitHub issueFirst of all, really useful, nice library! Already helped a lot to optimize components.
There is one warning I’m having trouble with:
Re-rendered because of prop changes
I’m getting this in a component which gets props injected by another component that I have no control over (managed by an npm library “react-color”). Some of these props are eg. an rgb object, which is a simple object containing “r”, “g”, “b” keys and even the value is the same, the object itself seems to be recreated by the component that injects these values.
I tried to fix this by adding a second parameter to my memo call:
const MyComponent = memo(props => {
return (<div>...<div>)
}, (prevProps, nextProps) => {
// deep compare prevProps, nextProps
})
This seems to remove the warning from “why-did-you-render” but I want to confirm if this is a good solution in this case? Thank you
Issue Analytics
- State:
- Created 3 years ago
- Comments:11
Top Results From Across the Web
Use React.memo() wisely
This post describes the situations when React.memo() improves the performance, and, not less important, warns when its usage is useless. Plus I' ...
Read more >When To Use React.memo() — And When Not To | by Ellon
React.memo() by default performs a props equality check to assert whether a component's render props are equal.
Read more >How to use React.memo() to improve performance
Learn how to use React.memo, some common pitfalls you might encounter, and why you shouldn't use React.memo for all your components.
Read more >What is React Memo and How to Use it? - Hygraph
Use it if your component is big enough (contains a decent amount of UI elements) to have props equality check. How to use...
Read more >React.memo, useMemo, useCallback | Geek Culture - Medium
Unlike the shouldComponentUpdate() method on class components, the areEqual function returns true if the props are equal and false if the props ......
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
Ah. So what I did previously was this:
your suggestion would be:
meaning if the props don’t change CustomPicker will not even get a chance to inject its own calculated props…sounds reasonable! I give it a quick test, the component doesn’t update for some reason in certain cases, but might be a bug I haven’t found yet. Thanks!
i mean