@wener/ui
Version:
22 lines • 725 B
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.useConstant = void 0;
const react_1 = __importDefault(require("react"));
/**
* create only once
*
* @see https://reactjs.org/docs/hooks-faq.html#how-to-create-expensive-objects-lazily
* @see https://github.com/Andarist/use-constant/blob/master/src/index.ts
*/
function useConstant(fn) {
const ref = react_1.default.useRef();
if (!ref.current) {
ref.current = { v: fn() };
}
return ref.current.v;
}
exports.useConstant = useConstant;
//# sourceMappingURL=useConstant.js.map