React JS - useMemo Hook

  • To stop any unnecessary background updates on updating state/props, useMemo hook is used.

  • Improves Performance.

  • It is used in Functional component.
Problem Statement :

In the following code, we have two buttons Update Count and Update Data and a function multiCount(). When we click on any of the above button, the function is being called in backend, but this function should be only called when we click on Update Count button. Since this function being called on any of button click, so it may effect performance of application. 

















The solution of above problem is to use useMemo Hook. In the below code, we have used useMemo and mentioned that multiCount() function will be only called when count is increased. This will improve performance of application.



Comments