Deprecated: Automatic conversion of false to array is deprecated in /home/u164338858/domains/areyoupop.com/public_html/wp-content/plugins/gs-facebook-comments/public/class-wpfc-public.php on line 258
useMemo and useCallback are two of the react hooks that help us in optimizing the performance of our application whenever components are re-rendered. They can be very useful in case you want to prevent some expensive computations from happening in your application (eg. an api call to the server that does some expensive calculations).
In this article, we will take a look on how to use these two hooks, what kind of problem do they solve and the difference between the two.
useMemo
The useMemo hook is used to return a memoized value. Memoization is a popular concept that refers to returning or reusing a cached value instead of computing it every time given the parameters used to calculate the value have not changed from the previous computation.
The official syntax of useMemo is useMemo(expensiveFunction, [dependencies]). From the syntax we can see that useMemo takes in two arguments. First argument is the expensive function call that we want to avoid while…