difference between useMemo and cache in react

87 Views Asked by At

In React we have latest new function called cache so what should be different between cache and useMemo hook in react

import {cache} from 'react';
1

There are 1 best solutions below

0
Reza Moosavi On

In general, you should use cache in Server Components to memoize work that can be shared across components. cache is recommended for memoizing data fetches, unlike useMemo which should only be used for computations.

At this time, cache should only be used in Server Components and the cache will be invalidated across server requests.