UNPKG

@sendbird/uikit-react

Version:

Sendbird UIKit for React: A feature-rich and customizable chat UI kit with messaging, channel management, and user authentication.

41 lines (37 loc) 1.35 kB
'use strict'; var React = require('react'); var SendbirdContext = require('./bundle-B19RHFpR.js'); function useDeepCompareMemoize(value) { var ref = React.useRef(value); if (!SendbirdContext.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) { React.useEffect(callback, dependencies.map(useDeepCompareMemoize)); } exports.useDeepCompareEffect = useDeepCompareEffect; //# sourceMappingURL=bundle-CxArG0ag.js.map