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