MCPcopy Create free account
hub / github.com/adobe/react-spectrum / useDeepMemo

Function useDeepMemo

packages/react-aria/src/utils/useDeepMemo.ts:17–30  ·  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 // oxlint-disable-next-line react/react-compiler
22 if (value && lastValue.current && isEqual(value, lastValue.current)) {
23 // oxlint-disable-next-line react/react-compiler
24 value = lastValue.current;
25 }
26
27 // oxlint-disable-next-line react/react-compiler
28 lastValue.current = value;
29 return value;
30}

Callers 2

useCalendarCellFunction · 0.90
useDateFormatterFunction · 0.90

Calls 1

isEqualFunction · 0.85

Tested by

no test coverage detected