react-native-vision-camera
Version:
VisionCamera is the fastest and most powerful Camera for react-native.
14 lines (13 loc) • 732 B
JavaScript
import { useMemo } from 'react';
/**
* Shallow-memoizes an array by flattening out
* the useMemo `deps` to {@linkcode maxComparisonLength}.
*/
export function useMemoizedArray(array, maxComparisonLength = 10) {
if (array.length > maxComparisonLength) {
throw new Error(`useMemoizedArray: Array's length (${array.length}) is greater than maxComparisonLength (${maxComparisonLength})! Cannot compare dependencies. Increase maxComparisonLength to a greater static value, and try again.`);
}
return useMemo(() => array,
// biome-ignore lint/correctness/useExhaustiveDependencies: We flatten out the array as dependencies. Cursed magic.
[...Array(maxComparisonLength).fill(0)].map((_, i) => array[i]));
}