How to use usememo hook in React Js?

useMemo() is an another hook in react js, which is used for the optimization purposes. It is similar to useCallback() hook, but the difference is that the useCallback() hook memoizes the function definition, whereas the useMem() hook memoizes the value. For example,

Memoizing a value is like caching a value so that it doesn’t need to be recalculated.

Syntax: const value = useMemo(functionThatCalculatesTheValue, dependencies);

useMemo() executes the functionThatCalculatesTheValue, only if the dependencies array got changed.

Leave a Reply

Your email address will not be published. Required fields are marked *