import { useRef } from 'react' type Init = () => T /** * Creates a constant value over the lifecycle of a component. */ export function useConstant(init: Init) { const ref = useRef(null) if (ref.current === null) { ref.current = init() } return ref.current }