UNPKG

@vtaits/use-lazy-ref

Version:

[![NPM](https://img.shields.io/npm/v/@vtaits/use-lazy-ref.svg)](https://www.npmjs.com/package/@vtaits/use-lazy-ref)

14 lines 330 B
// src/index.ts import { useRef } from "react"; var EMPTY_VALUE = Symbol("useLazyRef empty value"); var useLazyRef = (init) => { const resultRef = useRef(EMPTY_VALUE); if (resultRef.current === EMPTY_VALUE) { resultRef.current = init(); } return resultRef; }; export { useLazyRef }; //# sourceMappingURL=index.js.map