๐จ๐๐ฒ๐ ๐ฒ๐บ๐ผ ๐๐ผ๐ผ๐ธ ๐ถ๐ป ๐ฅ๐ฒ๐ฎ๐ฐ๐
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:
- A function to calculate a value.
- A list of dependencies.
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