UNPKG

@workday/canvas-kit-react

Version:

The parent module that contains all Workday Canvas Kit React components

20 lines (19 loc) 549 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useConstant = void 0; const react_1 = require("react"); /** * Get a constant value in React, only running the callback function once. `React.useMemo` does not * guarantee that a function will only be run once. * * @example * const value = useConstant(generateUniqueId) */ function useConstant(fn) { const ref = (0, react_1.useRef)(); if (!ref.current) { ref.current = fn(); } return ref.current; } exports.useConstant = useConstant;