MCPcopy
hub / github.com/adobe/react-spectrum / useDeepMemo

Function useDeepMemo

packages/react-aria/src/utils/useDeepMemo.ts:17–27  ·  view source on GitHub ↗
(value: T, isEqual: (a: T, b: T) => boolean)

Source from the content-addressed store, hash-verified

15import {useRef} from 'react';
16
17export function useDeepMemo<T>(value: T, isEqual: (a: T, b: T) => boolean): T {
18 // Using a ref during render is ok here because it's only an optimization – both values are equivalent.
19 // If a render is thrown away, it'll still work the same no matter if the next render is the same or not.
20 let lastValue = useRef<T | null>(null);
21 if (value && lastValue.current && isEqual(value, lastValue.current)) {
22 value = lastValue.current;
23 }
24
25 lastValue.current = value;
26 return value;
27}

Callers 2

useCalendarCellFunction · 0.90
useDateFormatterFunction · 0.90

Calls 1

isEqualFunction · 0.85

Tested by

no test coverage detected