question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Memo propsAreEqual is good practice to use?

See original GitHub issue

First 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:closed
  • Created 3 years ago
  • Comments:11

github_iconTop GitHub Comments

1reaction
andrewvargacommented, Apr 27, 2020

Ah. So what I did previously was this:

CustomPicker(memo(props => {
   ... impl
}))

your suggestion would be:

memo(CustomPicker(props => {
   ... impl
}))

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!

0reactions
vzaidmancommented, Apr 28, 2020

i mean

const ColorPicker = memo(CustomPicker(props => {
   ... component implementation
}))
ColorPicker .whyDidYouRender = false
export default ColorPicker 
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found