Files
volleyball-dev-frontend/node_modules/react-pdf/src/shared/hooks/useCachedValue.ts
2025-06-02 16:42:16 +00:00

24 lines
412 B
TypeScript

'use client';
import { useRef } from 'react';
import { isDefined } from '../utils.js';
export default function useCachedValue<T>(getter: () => T): () => T {
const ref = useRef<T | undefined>(undefined);
const currentValue = ref.current;
if (isDefined(currentValue)) {
return () => currentValue;
}
return () => {
const value = getter();
ref.current = value;
return value;
};
}