import { useRef } from 'react' ; const useConstant = < T > ( fn ) : T => { const ref = useRef < null | { value : T ; } > ( null ) ; if ( ref . current == null ) { ref . current = { value : fn ( ) } ; } return ref . current . value ; } ; export default useConstant ;