This repository has been archived on 2025-05-09. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
Astral-nook/resources/scripts/plugins/useDeepMemoize.ts

12 lines
347 B
TypeScript

import { DependencyList, MutableRefObject, useRef } from 'react';
import isEqual from 'react-fast-compare';
export const useDeepMemoize = <T = DependencyList> (value: T): T => {
const ref: MutableRefObject<T | undefined> = useRef();
if (!isEqual(value, ref.current)) {
ref.current = value;
}
return ref.current as T;
};