DEV Community

Cover image for 5 Small (Yet Easily Fixable) Mistakes Junior Frontend Developers Make With React Memoization

5 Small (Yet Easily Fixable) Mistakes Junior Frontend Developers Make With React Memoization

Ndeye Fatou Diop on February 15, 2024

I have reviewed more than 1,000 frontend pull requests. Like many junior developers, I made some common mistakes when I started,ย especially regard...
Collapse
 
brense profile image
Rense Bakker

only use useMemo when the value returned is a prop of a component that is wrapped in memo or if the function will be in the dependency list of a hook (for example, useEffect)

Great article, but I disagree with this part, because it assumes that code doesn't change. 5 months from now when we write a new useEffect hook, we don't remember which properties were memoized and which weren't.

I think the rule should be: memoize all application state that will always fail a strict equality check on the next rerender.

Collapse
 
_ndeyefatoudiop profile image
Ndeye Fatou Diop

Fun fact: in my day-to-day work, I apply this rule. But in this example, I didn't want to because, from what I read online, my situation is not the norm (I am working on a big enterprise app with hundreds of devs and a lot of changes).

Collapse
 
brense profile image
Rense Bakker

Agreed, it's not the norm, but it should be. It would prevent a lot of issues that React devs run into regularly right now.

Thread Thread
 
_ndeyefatoudiop profile image
Ndeye Fatou Diop

Hopefully with React compiler coming maybe this year, most of this wonโ€™t be needed anymore ๐Ÿ˜€