blakeblackshear.frigate/web/src/hooks/use-deep-memo.ts

13 lines
259 B
TypeScript
Raw Normal View History

2024-04-22 16:20:23 +02:00
import { useRef } from "react";
import { isEqual } from "lodash";
export default function useDeepMemo<T>(value: T) {
const ref = useRef<T | undefined>(undefined);
if (!isEqual(ref.current, value)) {
ref.current = value;
}
return ref.current;
}