Table of Contents

React - Memo (Cache)

About

Memoization is a React caching function that caches a computed value.

It

React memo is the equivalent of shouldComponentUpdate for a class component.

Usage

It will:

Example Usage

React.Memo wrapping a component

It's a higher-order component React.memo(), meaning it wraps a component

export default React.memo(function myFunctionComponent(props: any): any {
  // big computation
  return ();
});

UseMemo wrapping an object creation

const sameReference = useMemo(()=>["element1","element2"], [])

UseState as Memo

If the function does not have any dependencies

const [helloWorld] = useState(() => return "Hello World")