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.

Bug in useMemo (?)

See original GitHub issue

I noticed a problem with useEffect() - the second argument (changed props) which gets passed on through to useMemo(), is not respected: the effect is triggered every time anything updates; even if the component itself doesn’t update and another component on the page does.

As you can see in this example, the component should only update if count has changed - but the effect runs for all three components:

image

I narrowed it down to to useMemo(), where the last time triggers the change every time:

image

As you can see, it correctly detects that isChange is false - but still triggers the update, because isMounted is always undefined.

I will try to add a failing test for this problem.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mindplay-dkcommented, Oct 10, 2019

Looks good now, thanks!

0reactions
mindplay-dkcommented, Oct 10, 2019
Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't get latest state from parent component using usememo ...
usememo() doesn't get latest state from parent component. I am using usememo() hook api to solve flickering issue in rendering video preview ...
Read more >
When Using useMemo is A Really Bad Idea | by Lina Suodyte
In some cases useMemo might not retain our data in order to save memory so if we generate some data with the function...
Read more >
React.useMemo does not work to prevent re-renders
Use React.memo() instead to memoized components based on props. ... Do not rely on it to “prevent” a render, as this can lead...
Read more >
You're overusing useMemo: Rethinking Hooks memoization
In some cases, useMemo is irrelevant, overused, and harmful to your application performance. Learn these situations and how to avoid them.
Read more >
useMemo - React Docs
A calculation function that takes no arguments, like () => , and returns what you wanted to calculate. A list of dependencies including...
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