1const computeLetterCount = word => {
2 let i = 0;
3 while (i < 1000000000) i++;
4 return word.length;
5 };
6
7 // Memoize computeLetterCount so it uses cached return value if input array ...
8 // ... values are the same as last time the function was run.
9 const letterCount = useMemo(() => computeLetterCount(word), [word]);
1function moviePropsAreEqual(prevMovie, nextMovie) {
2 return prevMovie.title === nextMovie.title
3 && prevMovie.releaseDate === nextMovie.releaseDate;
4}
5
6const MemoizedMovie2 = React.memo(Movie, moviePropsAreEqual);