UNPKG

@winglet/react-utils

Version:

React utility library providing custom hooks, higher-order components (HOCs), and utility functions to enhance React application development with improved reusability and functionality

15 lines (12 loc) 339 B
import { useRef } from 'react'; import { isFunction } from '@winglet/common-utils/filter'; const useConstant = (input) => { const ref = useRef(undefined); if (!ref.current) { ref.current = { value: isFunction(input) ? input() : input, }; } return ref.current.value; }; export { useConstant };