DEV Community

Cover image for Cache your React event listeners to improve performance.

Cache your React event listeners to improve performance.

Charles Stover on June 02, 2019

An under-appreciated concept in JavaScript is how objects and functions are references, and that directly impacts React performance. If you were to...
Collapse
 
timkor profile image
Timkor

Interesting point of view. Did you test performance difference?

Collapse
 
charlesstover profile image
Charles Stover • Edited

There are too many variables to make a blanket statement that memoization will always improve performance of a Component. For some Components, memoization may take longer than a full re-render!

I discovered this issue specifically due to a performance problem in one of my applications that was re-rendering on a short interval. The event listeners were being recreated each interval, and the application slowed to a crawl as a result. Memoization removed the lag entirely.

This article hopefully just educates on how it works, and each developer can determine if and how best to apply it to their own projects.