import { MutableRefObject, useRef } from 'react' const EmptySymbol = Symbol('empty') /** * Allocates a ref and initializes it with a computed value. * * @param factory the factory is used during the initial render only to compute the ref's value * @typeParam T type of the generated value * @category Hook */ export function useComputedRef (factory: () => T): MutableRefObject { const ref = useRef(EmptySymbol) if (ref.current === EmptySymbol) { ref.current = factory() } return ref as MutableRefObject }