Files
med-notes/.pnpm-store/v10/files/37/6e5658d1698f5906278c7215f7ebe14665d2c71e87f2d035fc2f7e7a09f17350f36eb30102e6ec3cf9312fe8011a339160c8ada6165061a5a243600e994e64
2025-05-09 05:30:08 +02:00

16 lines
396 B
Plaintext

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