2020-08-25 21:25:31 -07:00
|
|
|
import { DependencyList, MutableRefObject, useRef } from 'react';
|
|
|
|
import isEqual from 'react-fast-compare';
|
|
|
|
|
2022-06-26 15:13:52 -04:00
|
|
|
export const useDeepMemoize = <T = DependencyList>(value: T): T => {
|
2020-08-25 21:25:31 -07:00
|
|
|
const ref: MutableRefObject<T | undefined> = useRef();
|
|
|
|
|
|
|
|
if (!isEqual(value, ref.current)) {
|
|
|
|
ref.current = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ref.current as T;
|
|
|
|
};
|