DEV Community

Discussion on: What is useMemo hook in React..

Collapse
 
seankimdev profile image
Sean Kim • Edited

Thank you for the awesome explanation! I’m excited to try this hook. I have a question though. Can you elaborate on why clicking the increment button rerenders the function although the count state is not changing as you stared below?

“But clicking the button 'Increment' also renders the evenNumDouble() function although the 'count' state is not changing”

Collapse
 
nasreenkhalid profile image
NasreenKhalid

When we click 'increment' button, the whole page is re-rendered therefore it executes every function without keeping in mind that clicking 'increment' button has no effect on 'evenNum' state and to restrict this unnecessary re-render we have used useMemo hook.

Collapse
 
seankimdev profile image
Sean Kim

Why does it rerender the entire page? Is it because it’s in the same component?

Thread Thread
 
nasreenkhalid profile image
NasreenKhalid

yes that's correct

Thread Thread
 
seankimdev profile image
Sean Kim

Got it. Thank you so much! :)

Thread Thread
 
nasreenkhalid profile image
NasreenKhalid

Pleasure :)