@sendbird/uikit-react
Version:
Sendbird UIKit for React: A feature-rich and customizable chat UI kit with messaging, channel management, and user authentication.
39 lines (36 loc) • 1.31 kB
JavaScript
import { useEffect, useRef } from 'react';
import { i as isEqual } from './bundle-BRRgVYI5.js';
function useDeepCompareMemoize(value) {
var ref = useRef(value);
if (!isEqual(value, ref.current)) {
ref.current = value;
}
return ref.current;
}
/**
* Custom hook that works like useEffect but performs a deep comparison of dependencies
* instead of reference equality.
*
* Best used when:
* - Working with complex objects without guaranteed immutability
* - Handling data from external sources where reference equality isn't maintained
* - Dealing with deeply nested objects where individual memoization is impractical
*
* Avoid using when:
* - Detecting changes within array items is crucial
* - Performance is critical (deep comparison is expensive)
* - Working primarily with primitive values or simple objects
*
* @example
* useDeepCompareEffect(() => {
* // Effect logic
* }, [complexObject, anotherObject]);
*
* @param callback Effect callback that can return a cleanup function
* @param dependencies Array of dependencies to be deeply compared
*/
function useDeepCompareEffect(callback, dependencies) {
useEffect(callback, dependencies.map(useDeepCompareMemoize));
}
export { useDeepCompareEffect as u };
//# sourceMappingURL=bundle-CJemq6cX.js.map