useMemo

up:: React Hooks What React useCallback is for functions, useMemo is for other values.

Eg, if we have an array that we sorted, React.memo still rebuilds the component every time because arrays are JS Non-primitives.

useMemo allows us to store the value.

const DemoList = props => {
	const { items } = props;
 
	const sortedList = useMemo(() => { // takes a function as an argument
	return items.sort((a,b) => a - b ); // returns value to store
	}, [items] // list of dependencies)
}

Of course, you also gotta use this in all parent components.

You will use React useCallback much more often though.