@workday/canvas-kit-react
Version:
The parent module that contains all Workday Canvas Kit React components
16 lines (15 loc) • 399 B
JavaScript
import { useRef } from '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)
*/
export function useConstant(fn) {
const ref = useRef();
if (!ref.current) {
ref.current = fn();
}
return ref.current;
}