Bug in useMemo (?)
See original GitHub issueI 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:
I narrowed it down to to useMemo()
, where the last time triggers the change every time:
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:
- Created 4 years ago
- Comments:6 (3 by maintainers)
Top 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 >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
Looks good now, thanks!
https://codesandbox.io/s/fre-demo-uxuic