๐—จ๐˜€๐—ฒ๐— ๐—ฒ๐—บ๐—ผ ๐—›๐—ผ๐—ผ๐—ธ ๐—ถ๐—ป ๐—ฅ๐—ฒ๐—ฎ๐—ฐ๐˜

Stop wasting CPU power in your React apps.

useMemo caches a value. It stops your app from running expensive code on every render.

It needs two things:

The code runs only when a dependency changes.

Example: You have a counter and an array. You calculate the max value of the array. Updating the counter should not trigger this calculation. useMemo solves this.

It holds the result until the array changes.

Source: https://dev.to/deva_i_932c8869ada96d4c9f/usememo-hook-in-react-4f8i