-
Notifications
You must be signed in to change notification settings - Fork 105
Expand file tree
/
Copy pathindex.ts
More file actions
15 lines (14 loc) · 784 Bytes
/
index.ts
File metadata and controls
15 lines (14 loc) · 784 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import {isEqual} from '@ver0/deep-equal';
import type {DependencyList} from 'react';
import {useCustomCompareMemo} from '../useCustomCompareMemo/index.js';
/**
* Like useMemo but validates dependency changes using deep equality check instead of reference check.
*
* @param factory Function calculating the value to be memoized.
* @param deps The list of all reactive values referenced inside `factory`.
* @returns Initially returns the result of calling `factory`. On subsequent renders, it will return
* the same value, if dependencies haven't changed, or the result of calling `factory` again, if they have changed.
*/
export function useDeepCompareMemo<T, Deps extends DependencyList>(factory: () => T, deps: Deps) {
return useCustomCompareMemo(factory, deps, isEqual);
}