UNPKG

react-pdf

Version:

Display PDFs in your React app as easily as if they were images.

16 lines (15 loc) 396 B
'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; }; }